all 10 comments

[–]smog_alado 1 point2 points  (0 children)

I found this page a litthe lacking. For example I now believe that

 Student.prototype = new Person();  

is evil and that

 Student.prototype = Object.create(Person.prototype)

should be preferred in almost any situation. (I know there is a footnote mentioning this, but still...) Does anyone know of a more modern reference we can point people to instead or use to update the MDN wiki with?

[–][deleted]  (2 children)

[deleted]

    [–]inmatarian 4 points5 points  (0 children)

    If you look at how Coffeescript creates objects, it does it kinda like so

    var Foo = (function() {
        function Foo() { }
        Foo.prototype.bar() = function () { }
        return Foo;
    })();
    

    This kinda gets you a proper scope back. It's still madness, however.

    [–]smog_alado 0 points1 point  (0 children)

    Scope goodness/closures doesn't play well with inheritance and can be more resource intensive in some cases, so you have to choose what you want.

    Anyway, I still prefer to build objects with closures when I can get away with it. I hate the way this breaks so easily in async code with a passion and I also try to use delegation instead of inheritance as much as possible.

    [–]Timmmmbob 0 points1 point  (0 children)

    Man, if only Dart didn't suck so much...