Skip to content

Instantly share code, notes, and snippets.

@bhaskarmelkani
Created February 9, 2018 13:09
Show Gist options
  • Save bhaskarmelkani/ca08792ba1afd39a241bd73fe8033fc4 to your computer and use it in GitHub Desktop.
Save bhaskarmelkani/ca08792ba1afd39a241bd73fe8033fc4 to your computer and use it in GitHub Desktop.
Object.keys(Array.prototype[Symbol.unscopables]); // -> ['copyWithin', 'entries', 'fill', 'find', 'findIndex', 'keys']
// Without unscopables:
class MyClass {
foo() { return 1; }
}
var foo = function () { return 2; };
with (MyClass.prototype) {
foo(); // 1!!
}
// Using unscopables:
class MyClass {
foo() { return 1; }
get [Symbol.unscopables]() {
return { foo: true };
}
}
var foo = function () { return 2; };
with (MyClass.prototype) {
foo(); // 2!!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment