Skip to content

Instantly share code, notes, and snippets.

@wentout
Last active November 26, 2020 14:45
Show Gist options
  • Save wentout/bfd158b88eb2ea9a4ecfb95b3daa815c to your computer and use it in GitHub Desktop.
Save wentout/bfd158b88eb2ea9a4ecfb95b3daa815c to your computer and use it in GitHub Desktop.
an example of Unbind via new keyword
'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
'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
@wentout
Copy link
Author

wentout commented Nov 26, 2020

Here is another example from:
https://gist.github.com/tadger/4572db07fa81f92d2cfd4bc4bedfeffd

  var unbind = Function.bind.bind(Function.bind);

  function instantiate(constructor, args) {
    return new (unbind(constructor, null).apply(null, args));
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment