from Hacker News

Introduction to Object-Oriented JavaScript - MDC Docs

by willyg on 5/4/11, 9:32 AM with 14 comments

  • by giberson on 5/4/11, 3:16 PM

    Under 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)?
  • by nprincigalli on 5/4/11, 1:30 PM

    Might want to check the Joose object system (http://joose.it/ #joose on irc.freenode.net), highly inspired in the awesome thing that 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/) :)
  • by clemesha on 5/4/11, 1:36 PM

    It'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.
  • by voidr on 5/4/11, 11:48 AM

    > Inheritance A Class can inherit characteristics from another Class.

    Somebody should tell Mozilla, that there are no classes in JavaScript....

  • by rgbrgb on 5/4/11, 2:36 PM

    I really like Mozilla's docs. I read this one recently actually.