4 ms·
In Jerboa, my JS-inspired scripting language, there's an alternative to the "function" keyword called "method". The only difference is that "method" functions e
by FeepingCreature 9y ago
In Jerboa, my JS-inspired scripting language, there's an alternative to the "function" keyword called "method". The only difference is that "method" functions expose `this' and "function" functions don't.
This removes the need for the `var self = this' hack and all the related weirdness.
An amusing consequence is that if you declare a simple closure as a method, its `this' pointer will be the stackframe of the lexical context where it is called.
method test() { print(this.a); }
var a = 5;
test(); /* implicitly __stackframe__.test() */
(You should not actually do this, of course. It's fun though.)
The reason is straightforward: the `this' pointer is the object on whose lookup the closure was found...