Last active
November 26, 2020 14:45
-
-
Save wentout/bfd158b88eb2ea9a4ecfb95b3daa815c to your computer and use it in GitHub Desktop.
an example of Unbind via new keyword
This file contains hidden or 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
'use strict'; | |
function anotherBeBound () { | |
debugger; | |
this.b = this.a; | |
if (!new.target) { | |
return this; | |
} | |
}; | |
anotherBeBound.prototype.a = 2; | |
const anotherBound = anotherBeBound.bind({a: 1}); | |
console.log((anotherBound()).b); // 1 | |
console.log((new anotherBound).b); // 2 |
This file contains hidden or 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
'use strict'; | |
function toBeBound () { | |
return this.a; | |
}; | |
toBeBound.prototype.a = 2; | |
const bound = toBeBound.bind({a: 1}); | |
console.log(bound()); // 1 | |
console.log((new bound).a); // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is another example from:
https://gist.github.com/tadger/4572db07fa81f92d2cfd4bc4bedfeffd