Skip to content

Instantly share code, notes, and snippets.

@jballanc
Created January 2, 2014 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jballanc/8220710 to your computer and use it in GitHub Desktop.
Save jballanc/8220710 to your computer and use it in GitHub Desktop.
// 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