Skip to content

Instantly share code, notes, and snippets.

@adamterlson
Last active April 5, 2016 13:48
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 adamterlson/629423a23441c95f802c623f08a08308 to your computer and use it in GitHub Desktop.
Save adamterlson/629423a23441c95f802c623f08a08308 to your computer and use it in GitHub Desktop.
Testing this context on class instance methods
const c = (function () {
this.context = 'lexical context';
const bar1 = () => {
console.log('bar 1:', this.context);
};
const curry = (fn) => {
console.log('bar 3 curryer context:', this.context);
return () => {
console.log('bar 3:', this.context);
};
}
return class Foo {
constructor() {
this.context = 'instance of class';
}
context = "static class";
bar1 = bar1;
bar2 = () => {
console.log('bar 2:', this.context);
};
bar3 = curry();
bar4 = ((fn) => {
console.log('bar 4 curryer context:', this.context);
return () => {
console.log('bar 4:', this.context);
};
})();
}
}).call({});
const d = new c();
console.log('Instantiated');
d.bar1();
d.bar2();
d.bar3();
d.bar4();
/**
* OUTPUT:
* bar 3 curryer context: lexical context
* bar 4 curryer context: static class
* Instantiated
* bar 1: lexical context
* bar 2: instance of class
* bar 3: lexical context
* bar 4: instance of class
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment