Created
November 11, 2015 04:22
-
-
Save tuchida/0ad149bb054d71a55903 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
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