Re:Crafting Interpreters: Superclasses
by munificent on Wednesday March 18, 2020 @01:44PM
(#22619257)
Lox makes a distinction between functions and methods, so you won't run into this problem. This is unlike JavaScript, but like most other object-oriented languages.
If you take a function (which may be a reference to a method) and store it in a field on some instance, the function remembers its original bindings to "this" and "super", which is generally what you want and expect.
Lox doesn't allow you to mutate a class by adding new methods to it.
If you take a function (which may be a reference to a method) and store it in a field on some instance, the function remembers its original bindings to "this" and "super", which is generally what you want and expect.
Lox doesn't allow you to mutate a class by adding new methods to it.