Created
October 17, 2012 07:08
-
-
Save t-uda/3904150 to your computer and use it in GitHub Desktop.
new 演算子を使いつつ可変長引数っぽいことをするには? ref: http://qiita.com/items/60817eeaab857b2fb316
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
function Hoge (a) { | |
this.x = a; | |
} | |
var a = new (function () { return Hoge.apply(this, ["hoge"]); })(); | |
a instanceof Hoge; // => false |
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
a = Array.apply(null, [1,2,3]); |
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
a = new (function () { return; })(); | |
Hoge.apply(a, ["hoge"]); |
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
var a = new (function () { return Array.apply(this, [1,2,3]); })(); |
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
var a = new (Hoge.bind.apply(Hoge, [null].concat(["hoge"])))(); | |
a instanceof Hoge; // => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment