M
Michael Haufe (\TNO\)
Am I correct that in ES3, this is the most straightforward way to call
a constructor with variable arguments?
----------
function Point(){
if(!(this instanceof Point)){
var args = [];
for(var i = 0, len = arguments.length; i < len; i++)
args = "arguments[" + i + "]";
return eval("new Point(" + args + ")");
}
this.x = arguments[0];
this.y = arguments[1];
}
Point.prototype.toString = function(){
return "(" + this.x + "," + this.y + ")";
}
var p1 = new Point(1,2);
var p2 = Point(3,4);
WScript.Echo(p1.toString())
WScript.Echo(p2.toString())
a constructor with variable arguments?
----------
function Point(){
if(!(this instanceof Point)){
var args = [];
for(var i = 0, len = arguments.length; i < len; i++)
args = "arguments[" + i + "]";
return eval("new Point(" + args + ")");
}
this.x = arguments[0];
this.y = arguments[1];
}
Point.prototype.toString = function(){
return "(" + this.x + "," + this.y + ")";
}
var p1 = new Point(1,2);
var p2 = Point(3,4);
WScript.Echo(p1.toString())
WScript.Echo(p2.toString())