Created
January 2, 2014 15:17
-
-
Save jballanc/8220710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// So, ECMAScript 6 Harmony arrow_function_syntax says: | |
// ----8<----8<----8<---- | |
// ''=>'' has only lexical ''this'', no dynamic ''this'' | |
const obj = { | |
method: function () { | |
return () => this; | |
} | |
}; | |
assert(obj.method()() === obj); | |
let fake = {steal: obj.method()}; | |
assert(fake.steal() === obj); | |
// But ''function'' still has dynamic ''this'' of course | |
let real = {borrow: obj.method}; | |
assert(real.borrow()() === real); | |
// ----8<----8<----8<---- | |
// So what about this: | |
cons obj = { | |
method: function() { | |
return () => function() { | |
this; | |
} | |
} | |
} | |
assert(obj.method()()() == obj), | |
let fake = { steal: obj.method()}; | |
assert(fake.steal()() === /*???*/ ); | |
// Is 'this' from the innermost function inheriting the object dynamic scope, | |
// same as the outermost function? Or does the lexical 'this' from the middle | |
// arrow scope get dynamically inherited by the innermost function? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment