Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This isn't really about prototypal inheritance. If you wrote methods like this in Ruby, you would have the same issue:

    Klass.method := lambda { p self }
Also, if JavaScript looked like this, you wouldn't need the fat arrow:

    // Let's call this a "prototype function"
    Klass.prototype.function method() {
      …
    }
Together with these rules:

* A function always captures its outer `this`

* The getter of a prototype function (`thing.method`) always returns a binded function (where `this` == `thing`).



Absolutely. I don't mean that dynamic "this" is required by prototypal inheritance in general -- I mean that it's required because of JavaScript's particular implementation of prototypes, where they're exposed to you as a value, but there's no syntax where the language can tell that you're in the process of building one out.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: