1 2 Function.prototype.New = 3 Function.prototype.newInstance = function(){ 4 for(var i=0,arg=[];i<arguments.length;i++) arg.push("arguments["+i+"]"); 5 eval("var ins = new this("+arg.join(",")+")"); 6 return ins; 7 } 8 9 // example 10 11 // way to get [1,2,3] 12 new Array(1,2,3) 13 Array.New(1,2,3) 14 Array.newInstance(1,2,3) 15 16 // getClass and newInstance 17 var foo = []; 18 foo.constructor.New("12345") // [12345] 19 20 var foo = ""; 21 foo.constructor.New("12345") // "12345"
You need to create an account or log in to post comments to this site.