Skip to content

Instantly share code, notes, and snippets.

@jmshal
Forked from DmitrySoshnikov/es78-this-scope.js
Created September 13, 2016 02:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmshal/5a86ed22fdc9eec973701fe67a81edb2 to your computer and use it in GitHub Desktop.
Save jmshal/5a86ed22fdc9eec973701fe67a81edb2 to your computer and use it in GitHub Desktop.
/**
* JS scoping, and this property resolutions rules in ES7/ES8.
*
* Quiz: x is gone, and x is everywhere!
*
* Help find Xs! What's the output?
*/
let x = 1;
({
x: 2,
run() {
(new class X {
x = 3;
static x = 4;
getX = () => {
return this.x;
};
static getX = () => {
return this.x;
};
exec() {
console.log(X.getX() + this.getX());
}
}).exec();
}
}).run(); // ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment