extend

Methods

KISSY.extend()
Function KISSY.extend (SubClass,ParentClass[,prototypeMembers,staticMembers])
让子类 SubClass 继承父类 ParentClass
Parameters:
  • SubClass (function) – 将要继承的子类函数
  • ParentClass (function|object) – 继承自的父类函数
  • prototypeMembers (object) – 需要添加/覆盖的原型成员
  • staticMembers (object) – 需要添加/覆盖的静态成员.
Returns:

SubClass

Return type:

function

例如:

var S = KISSY;

function Bird(name) { this.name = name; }
Bird.prototype.fly = function() { alert(this.name + ' is flying now!'); };

function Chicken(name) {
    Chicken.superclass.constructor.call(this, name);
}
S.extend(Chicken, Bird,{
    fly:function(){
        Chicken.superclass.fly.call(this)
        alert("it's my turn");
    }
});

new Chicken('kissy').fly();

Note

子类方法中可通过 superclass 来访问父类函数的原型, 进而调用父类方法.