newInstance

  • function
can.Construct.newInstance  

Returns an instance of can.Construct. This method can be overridden to return a cached instance.

can.Construct.newInstance([...args])

Parameters

  1. args {*}Optional

    arguments that get passed to setup and init. Note that if setup returns an array, those arguments will be passed to init instead.

Returns

{class}

instance of the class

Creates a new instance of the constructor function. This method is useful for creating new instances with arbitrary parameters. Typically, however, you will simply want to call the constructor with the new operator.

Example

The following creates a Person Construct and then creates a new instance of Person, using apply on newInstance to pass arbitrary parameters.

var Person = can.Construct.extend({
  init : function(first, middle, last) {
    this.first = first;
    this.middle = middle;
    this.last = last;
  }
});

var args = ["Justin","Barry","Meyer"],
    justin = new Person.newInstance.apply(null, args);