3 ms·
> JavaScript is forced to make the pessimal choice of only ever having dynamic-bound "this", because of that favorite whipping boy ... prototypal inheritance.
by masklinn 15y ago
> JavaScript is forced to make the pessimal choice of only ever having dynamic-bound "this", because of that favorite whipping boy ... prototypal inheritance.
I don't think that's true: functions accessed via objects could very well be bound to the object (that's what Python does, accessing a method via an object instance returns a "bound method" which is curried with the instance, whereas accessing the same method via the class returns an "unbound method" which requires a class instance as its first argument).
- jashkenas 15y agoThat works in Python, because Python has a distinction between an "instance" object, and, say, a Dict. In JavaScript an object is an object is an object -- under your proposed change, what would be the value of "this, in this: Klass.prototype.method = options.method;
- masklinn 15y ago> That works in Python, because Python has a distinction between an "instance" object, and, say, a Dict. Not really, it's trivial to create a dict-like object which allows access to keys as properties, just override `__getattr__`. > In JavaScript an object is an object is an object No, objects can have a non-null [[prototype]] indicating it was created from using `new` on a constructor. > Klass.prototype.method = options.method; Depends what `options` is.