125 Comments
- Scyth3, on 12/20/2007, -3/+78This quite possibly is the worst, and least descriptive/indepth tutorial ever. How is this dugg up so high?
- gcnaddict, on 12/20/2007, -3/+50"It also touches on how Object Oriented Programming differs from Java and C++."
Uhm, excuse me. Java is an object oriented language. I'm not even going to bother reading the link; ***** description warrants a bury. - spickly, on 12/20/2007, -2/+28it says ajax and javascript
- markstory, on 12/20/2007, -1/+20Such a shallow comparison of Javascript to anything. Didn't do any of the comparisons promised. Lame.
- recover82, on 12/20/2007, -5/+23The description of this link tells how the tutorial discusses.. "...how Object-Oriented Programming differs from Java and C++".....
What the deuce? Java and C++ ARE OOP languages!!
The guy who posted this is a douche-bag. - josefresco, on 12/20/2007, -1/+18behold the power of the "shout"
- radicaldementia, on 12/20/2007, -1/+15Yeah, this article doesn't explain anything, makes me wonder if the people who dugg it up even read it or even know what javascript is. If anyone is really looking for a better tutorial, just google OOP Javascript and you'll get far better results.
- achoi, on 12/20/2007, -1/+12"It also touches on how Object Oriented Programming differs from Java and C++."
you just failed the buzzword bingo. - Chandon, on 12/20/2007, -1/+12Talking about "object oriented programming languages" is sort of missing the point. Java and C++ each provide explicit support for some (but not all) of the techniques that are generally associated with object oriented programming. Other languages provide support for a different set of those techniques. The most basic techniques of object oriented programming - the abstract data type pattern - can be implemented in any language. Other techniques - like multimethods, which are not provided in either C++ or Java - are really obnoxious to use without language support. But saying that your favorite language is "object oriented" and other languages aren't is silly - in the end "object oriented" is just a set of design patterns on top of an imperative programming style.
- Tippis, on 12/20/2007, -1/+11Because http://www.google.com/search?q=%2Bobject-oriented+ ... would be too easy ;)
- binnicario, on 12/20/2007, -0/+10From someone who's working on a project with over 100 thousand (yes, one hundred thousand) lines of JavaScript.
1. Seasoned JavaScript developers prefer creating empty objects with the "empty object literal" {} versus "new Object()"
2. "AnchorName.CreateObject" is really quite awkward. He could just say AnchorRename = new function(...) { body of the constructor } and then set the prototype object of AnchorRename directly. That way, all you have to say is "new AnchorRename()"
3. For anchor renaming, he didn't necessarily have to create a new class. He could have just made a function that returns another function. JavaScript indeed supports higher-order functions.
And despite the comments of those above, Javascript, despite its funny-looking object oriented syntax, is quite a *powerful* OO language with single inheritance, weakly typed, with closures. Think of Python. - Homunculiheaded, on 12/20/2007, -0/+10"I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." -- Alan Kay
Many OOP purists consider both C++ and Java to be relatively poor implementations of OOP. There are many different ways to do OOP and the author was simply saying that the way JavaScript implements OOP is different than the way C++ or Java do it. Also look at SmallTalk, or Lisp's CLOS to see other implementations that differ from what Java calls OOP, both of which are systems many people feel are more closely tied to the ideals of OOP. - josho, on 12/20/2007, -1/+9i just logged in to say this is absolutely awful and pointless. buried.
horribly written, lack of information, and the author basically defines non-expert *****.
and.. ajaxonomy? jesus. christ. http://*****.com wean yourself off the teat of buzzword hype and gain some substance to your life, please. - johnnysaucepn, on 12/20/2007, -0/+8So, exactly which language specification is Flash ActionScript based on? Hint: it also goes by the name ECMAScript...
- VanD, on 12/20/2007, -3/+10Anyone interested in Java and C++ already know how C++ and Java differ...
What is the point of this *****?
Plus Java is OO - This doesn't make any sense. - shredswithpiks, on 12/20/2007, -3/+9you win the prize for "post exactly what everyone should be thinking!"
- andycr512, on 12/20/2007, -4/+10I would never, ever want to code in JavaScript again after doing two commercial game projects for 3 years which used a client-side variant of it for all game logic. You don't want to know how unmaintainable 16,000 lines of JavaScript game logic becomes - especially when it's just the cutscene system.
- MeatBiProduct, on 12/20/2007, -0/+5i bet you can shove jquery up your ass faster than you convince people you're a decent programmer by pushing a framework over basic syntax structure.
- trib4lmaniac, on 12/21/2007, -0/+5Static typing is not stopping C++ from being a full OO programming language - C#, for instance, is statically typed.
- floydman, on 12/20/2007, -3/+8burried without reading article.
"Object Oriented Programming differs from Java and C++." was enough - Chandon, on 12/20/2007, -1/+6JavaScript was designed to use objects, so worrying about object overhead is premature optimization - which is the root of all evil.
- Comatose51, on 12/20/2007, -2/+7You're wasting your time with comments like that on Digg. Most of the people here can't tell you the difference between a closure and a function pointer or even heard of either one. They've read a book on Java or taken a course on it and think they're software engineers because of that.
- inactive, on 12/20/2007, -1/+6A much easier way to do OOP in JavaScript than what's presented in the article:
myClass = {
myFunction: function(paramOne, paramTwo) {
// code here
}
Then just access it like a normal JS methods: myClass.myFunction('paramOneValue', 'paramTwoValue'); - Shakermaker, on 12/20/2007, -1/+5I'm thinking quite a few...
- init100, on 12/20/2007, -0/+4"Javascript is a functional programming language."
I'd rather say that Javascript has elements from both functional, imperative and object-oriented languages. - bahamutxd, on 12/20/2007, -1/+5C++ isn't strict on enforcing OOP. You can still write procedural C++ code. Languages like Ruby or Smalltalk are pure OOP languages. Dynamic Typing is another thing that C++ lacks. Not everything in C++ is an object.
- shredswithpiks, on 12/20/2007, -0/+4hey man, it's cool if you want to code everything in legacy C....
- saifatlast, on 12/20/2007, -1/+5Go to your history, click undigg, then come back and bury.
- andycr512, on 12/20/2007, -0/+4I wasn't in charge of anything; they chose an engine which had a custom version of JavaScript embedded deep in the engine. You -could- code for it in C++, but dare I say the interface for C++ was uglier than just going with Javascript... The engine was A6 (now A7, which apparently now supports a C-ish language, so perhaps it isn't as bad anymore. I haven't worked with it for years. Their old "C-script" was nothing like C; it was the Javascript.)
The irony to your suggestion is that I now head a development project working on a game engine which uses Python as its scripting language. - binnicario, on 12/20/2007, -0/+4Except that you're only creating one oject.
You can say:
MyClass = function (constructor, arguments) { constructor; body; here; }
MyClass.prototype = {
eatGrass: function(grass) { grass.eat(this); }
drinkWater: function(water) { this.waterDrank_++; }
} - MeMongo, on 12/20/2007, -1/+4You can still undigg in your user profile
- init100, on 12/20/2007, -1/+4Sounds ugly. Why not rather use Python or Lua? They seem like better alternatives for a game extension language.
- inactive, on 08/11/2008, -0/+3You guys who are burying him do not understand what "fully OOP" is. "Fully OOP" is where *everything* is an object. Fully OOP languages are JavaScript, Java, Ruby, and SmallTalk
- DemonWasp, on 12/20/2007, -0/+3I'm coding OO-JS as my job right now, and I can tell you that even when using a big framework (such as Yahoo's, http://developer.yahoo.com/yui/), you really can't see very much of a slowdown. Compared with the length of a page-load, JS times are completely negligible, except in certain cases.
Assuming you're not ray-tracing in your javascript, and you use animations sparingly (as you always should), the page will be fast and responsive. To make things (appear) even better, try hiding elements while you do the expensive DOM-manipulation; it makes it appear way faster when everything appears at once instead of coming in piece by piece. I'm using this strategy during XHR calls from my module right now, and the page just feels way, way faster than it did when I let it show me the drawing.
On a related note, I wish Digg would let me turn off that stupid JS animation used in the comments, because it doesn't look good on older machines. - mrjava241, on 12/20/2007, -0/+3When I think of OO programming, I think Java and C#, C# in particular, very cool features.
- units, on 12/20/2007, -0/+3Is there much overhead associated with using objects in an interpreted language like JavaScript?
No. In general, adding objects to a language is not a noticeable performance hit, as it's roughly the same as storing structs in dynamic memory and passing an implicit parameter as a reference ('this') to each function. There's a little bit of added processing necessary to massage this behavior out of the myriad of ways you can create objects in JS, but I'd be very surprised if there were any appreciable overhead, given the nature of JS.
Prototype.js uses objects, does it not?
Absolutely. I think you'll find that OO in Javascript is the cleanest way possible to develop, maintain and refactor large amounts of Javascript, should be in the semi-unfortunate position to have to do such a thing. Few people love developing very, very large systems in C now that alternatives are available, for some of the same reasons that procedural JS suffers from. - eggie5, on 12/20/2007, -0/+3I could swear I've been using object oriented javascript for a while now... hmm...
- init100, on 12/20/2007, -0/+3Why is OOP such a bad invention? It cuts down on my work since I'm able to extend existing classes and only add the differences.
- andycr512, on 12/20/2007, -0/+3They were client-side 3D PC games; they never touched a browser.
- inactive, on 12/20/2007, -0/+2/******** Creating a JavaScript Class *******/
function MyClass(param0, param1) {
this.name = param0;
this.say = function(s) {
alert(this.name + ' is saying ' + s);
}
}
MyClass.classVar = 'OK';
var i = new MyClass('Donkey', 67);
alert(i.name);
i.say(MyClas.classVar);
/******** Inheritence *******/
function SubClass(param0) {
this.name = param0;
this.dance = function() {
alert(this.name + ' is dancing');
}
}
// SubClass inherits from MyClass
SubClass.prototype = new MyClass();
var s = new SubClass('Rocker');
s.say('meh');
Cool? - rickcarson, on 12/20/2007, -0/+2I find GWT is even cleaner. I can put classes in their own files and go wild and crazy with all the sub-classing you could shake an interface at.
- DemonWasp, on 12/20/2007, -0/+2@looksliketrent: Honestly, if you run your JS through a compressor (i.e., remove whitespace and such) beforehand, then it'll be a relatively small download. Remember that a lot of lines in code are blank or { or } or ; . Sure, it's a relatively large page load, and your browser needs a lot of RAM for it, but you're probably making up for it by using JS rather than going to the server a lot.
@OP: You're absolutely correct on all points, but I would warn you that if you have assignments to "empty object literal" in the prototype, that causes some issues. Also, run your code through JSLint (http://www.jslint.com/) until it passes and it'll make your life a little bit simpler. - init100, on 12/20/2007, -0/+2"in the end "object oriented" is just a set of design patterns on top of an imperative programming style."
Are you saying that you cannot have object-oriented non-imperative programming languages, such as OO functional languages? - init100, on 12/20/2007, -0/+2Could you expand on this? I'm curious why you would argue that Java and C++ are not "native" OOP languages. What about other languages, such as Python?
- TeagueSterling, on 12/21/2007, -0/+2Those videos are really great, I would recommend them to anyone who uses Javascript and has any bit of confusion about the language. His site is also very useful: http://javascript.crockford.com/
- MeatBiProduct, on 12/20/2007, -0/+2seriously - you're like the other programmers i've worked with in the past. you're taking things literal when its implied. What it means but doesn't read is this "JavaScript differs from other OO languages".
- Zach978, on 12/21/2007, -0/+2I think OO programming is easier!
- bahamutxd, on 12/21/2007, -0/+2The choice of OO vs. Procedural depends on the problem. If you're using a few simple JS functions, it'd be ridiculous to go the OO route.
- kroenecker, on 12/20/2007, -0/+2The actual quote since no-one seems able to quote things: "how JavaScript object oriented programming differs from these coding languages". In other words, he is stating that there is a difference. And, in that he shows the user how to create a slightly more re-usable function, he doesn't address the true power of OOP, inheritance (well, and polymorphism, but I don't think Javascript does polymorphism).
...Unless of course he's updated the page since you all made your comments :D - Topher06, on 12/20/2007, -0/+2This is a very Web 2.0 article.
-
Show 51 - 100 of 125 discussions




What is Digg?
Browsing Digg on your phone just got easier with our enhancements to the