Last active
April 5, 2016 13:48
-
-
Save adamterlson/629423a23441c95f802c623f08a08308 to your computer and use it in GitHub Desktop.
Testing this context on class instance methods
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
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