extend

  • function
can.Construct.extend  

can.Construct.extend([name,] [staticProperties,] instanceProperties)

Extends can.Construct, or constructor functions derived from can.Construct, to create a new constructor function. Example:

Animal = can.Construct.extend({
  sayHi: function(){
    console.log("hi")
  }
})
var animal = new Animal()
animal.sayHi();

Parameters

  1. name {String}Optional

    Creates the necessary properties and objects that point from the window to the created constructor function. The following:

    can.Construct.extend("company.project.Constructor",{})
    

    creates a company object on window if it does not find one, a project object on company if it does not find one, and it will set the Constructor property on the project object to point to the constructor function.

    Finally, it sets "company.project.Constructor" as fullName and "Constructor" as shortName.

  2. staticProperties {Object}Optional

    Properties that are added the constructor function directly. For example:

    Animal = can.Construct.extend({
      findAll: function(){
        return can.ajax({url: "/animals"})
      }
    },{});
    
    Animal.findAll().then(function(json){ ... })
    

    The static setup method can be used to specify inheritable behavior when a Constructor function is created.

  3. instanceProperties {Object}

    Properties that belong to instances made with the constructor. These properties are added to the constructor's prototype object. Example:

    Animal = can.Construct.extend({
      init: function(name){
        this.name = name;
      },
      sayHi: function(){
        console.log(this.name,"says hi")
      }
    })
    var animal = new Animal()
    animal.sayHi();
    

    The init and setup properties are used for initialization.

Returns

{function()}

The constructor function.