5 ms·
Introduction to Object-Oriented JavaScript - MDC Docs
- voidr 15y ago> Inheritance A Class can inherit characteristics from another Class. Somebody should tell Mozilla, that there are no classes in JavaScript....
- sjs 15y agoPlease don't make us start saying "object used as a class".
- voidr 15y agoThe first step to learning JavaScript is to forget about class-ical OOP, you can't write good code if you start forcing class-ical concepts on JavaScript, it's a prototypical language encouraging people to treat it as something else is wrong.
- sjs 15y agoWhen a language has a deficiency people make up for it with libraries. If you don't acknowledge the "class pattern" for object inheritance then you are dismissing an incredibly popular use of OO. Whether or not code reuse via OO is a good thing or not is a whole other debate though. I don't try to warp every problem into a class hierarchy, but sometimes it's a useful conceptual tool.
- erez 15y agoThe guide says that immediately after the terminology paragraph
- johncoltrane 15y agoBut comes back to it at the Custom Objects part(1). And everywhere. They don't use "class" as a keyword, though, but more in a CS way which can be problematic because other keywords like "prototype", "array" or "object" mean pretty much the same thing in both contexts. An interesting ressource, anyway. (1) https://developer.mozilla.org/en/Introduction_to_Object-Oriented_JavaScript#Custom_Objects https://developer.mozilla.org/en/Introduction_to_Object-Orie...
- johncoltrane 15y agoThe document is probably targeted at newcomers from other languages. But still…
- nprincigalli 15y agoMight want to check the Joose object system (http://joose.it/ http://joose.it/ #joose on irc.freenode.net), highly inspired in the awesome thing that Moose (http://search.cpan.org/dist/Moose/ http://search.cpan.org/dist/Moose/) is to Perl. There's even a port of KiokuDB as KiokuJS!(http://joose.it/blog/2011/01/13/introducing-kiokujs/ http://joose.it/blog/2011/01/13/introducing-kiokujs/) :)
- clemesha 15y agoIt's good to know this stuff, but in my real-world usage of JavaScript, I've become a big fan of Backbone.js to help structure code intelligently, etc.
- rgbrgb 15y agoI really like Mozilla's docs. I read this one recently actually.
- giberson 15y agoUnder the section "The Property (object attribute)" the code segment has two curious lines. I expect the first cancels out the latter, making the latter useless. // in Person function this.gender = gender; // outer scope (gender will never be this value because it is overridden by the person constructor argument) Person.prototype.gender = 'Person Gender'; Am I correct, or does the prototype.gender line have some other purpose than instantiating gender to a value that is immediately overridden by the passed in value (or undefined if no value is passed)?
- qqqq2010 15y agoIt's ensuring a default value basically. If you instantiate a person without an argument and try to reference this.gender later, you'll throw a script error. This is just avoiding that. A way I'd prefer might look like this: function Person = function(gender) { this.gender = gender || 'neuter' //the sauce that defines a fallback }
- giberson 15y agoThis is not the case, because in the constructor person is being set to the argument. If the argument is not supplied (undefined), calling the instantiated object's gender property will result in undefined. [tested and confirmed]
- juliangutman 15y agoPresumably if the gender property is deleted the prototype.gender will come through