Created
February 9, 2018 13:09
-
-
Save bhaskarmelkani/ca08792ba1afd39a241bd73fe8033fc4 to your computer and use it in GitHub Desktop.
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
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