can-symbol
Version:
Well known symbols used to detail how to operate on different objects
28 lines (21 loc) • 946 B
Markdown
constructor function or prototype object.
`@ .new(...args)`
The `@@@ .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);
};
```
{*} A callable constructor or a prototype object.
{*} args pass any number of parameters of any type
{Object} A new instance of the type.
{function(...)} can-symbol/symbols/new can.new
can-symbol/symbols/call
Create a new instance of a