3 ms·
> Lox will also have this quirk, won't it? Possibly - I’m not sure about the details of method lookup in Lox. Does `this` even work correctly when a method is
by pansa2 7y ago
> Lox will also have this quirk, won't it?
Possibly - I’m not sure about the details of method lookup in Lox. Does `this` even work correctly when a method is assigned to an instance?
- munificent 7y agoIf you store a function or reference to a method in a field on an instance in Lox, the function will remember its original `this` binding. That's what Python, C#, Ruby, etc. do and is generally what you want. It's not what JS does because JS doesn't really know what a "method" is, or at least didn't before classes were added.
- pansa2 7y agoIs it possible that there isn't a `this` binding? Does Lox allow access to "unbound" methods directly from a class, or are methods accessible only via instances?
- munificent 7y agoMethods are only accessible from instances, so `this` is always meaningfully bound. If you try to use `this` outside of a class body, it's a static error.
- pansa2 7y agoOK, that solves the problem. The issue with unbound methods in Python is that they don’t yet have a value for `this`, but they do have a fixed value for `super`.