can.new
Create a new instance of a constructor function or prototype object.
@@can.new(...args)
The @@can.new
symbol points to a function that constructs and returns a new instance object. It is left to the
implementation to create the object, set the prototype chain, and handle any arguments passed to the constructor.
function constructor() {}
constructor.prototype = { foo: "bar" };
// ES6 rest and spread params used below to be concise.
constructor[canSymbol.for("can.new")] = function(...args) {
return new this(...args);
};
var prototype = { baz: "quux" };
prototype[canSymbol.for("can.new")] = function(props) {
return Object.create(this, props);
};
Parameters
- args
{*}
:pass any number of parameters of any type
Returns
{Object}
:
A new instance of the type.