3 ms·
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 } A
by judofyr 15y ago
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`).
- jashkenas 15y agoAbsolutely. 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.