Skip to content

Instantly share code, notes, and snippets.

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