Как передать неопределенное количество аргументов в функцию-конструктор при создании экземпляра?
Как более изящно сделать -
function Test( a, b ){
this.a = a;
this.b = b;
}
var test = new Test.call( ..., 1, 2 );
Обновлено:
function create( ){
var type = arguments[0],
length = arguments.length,
args = [],
instence = Object.create( type.prototype );
while( length-- > 1 ){
args[length - 1] = arguments[length];
}
return type.apply( instence, args );
}
create( Test, 2, 3 )
Источник: Stack Overflow на русском