Re:Asm-Dom – WebAssembly Virtual DOM
by masklinn on Sunday May 21, 2017 @06:00AM
(#14386543)
> Fat arrow functions bind "this" to whatever the surrounding context is
They don't actually bind `this` at all, there is a slot on the function object ([[ThisMode]] in the spec) which describes how to resolve `this` references for the function's body, for arrow function the mode is "lexical" and they simply grab the this reference from their lexical environment[0] as if it were any other non-local variable.
In fact, lexical resolution is the default, so what happens is during [[Call]][1] arrow functions will simply skip all the hard work in OrdinaryCallBindThis[2] by early-returning while the other two types (strict and global) have to resolve their thisValue then bind their local environment.
They don't actually bind `this` at all, there is a slot on the function object ([[ThisMode]] in the spec) which describes how to resolve `this` references for the function's body, for arrow function the mode is "lexical" and they simply grab the this reference from their lexical environment[0] as if it were any other non-local variable.
In fact, lexical resolution is the default, so what happens is during [[Call]][1] arrow functions will simply skip all the hard work in OrdinaryCallBindThis[2] by early-returning while the other two types (strict and global) have to resolve their thisValue then bind their local environment.
[0] https://www.ecma-international.org/ecma-262/6.0/#sec-lexical...
[1] https://www.ecma-international.org/ecma-262/6.0/#sec-ecmascr...
[2] https://www.ecma-international.org/ecma-262/6.0/#sec-ordinar...