Skip to content

Instantly share code, notes, and snippets.

@tuchida
Created November 11, 2015 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuchida/0ad149bb054d71a55903 to your computer and use it in GitHub Desktop.
Save tuchida/0ad149bb054d71a55903 to your computer and use it in GitHub Desktop.
class MyClass {
constructor(a, b, c) {
this.sum_ = a + b + c;
}
sum() {
return this.sum_;
}
}
console.log(new MyClass(2, 3, 4).sum());
var applyNew = function(ctor, args) {
var bind = Function.prototype.bind;
var c = bind.apply(ctor, [null].concat(args));
return new c();
};
console.log(applyNew(MyClass, [2, 3, 4]).sum());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment