Heim  >  Artikel  >  Web-Frontend  >  ExtJS4中使用mixins实现多继承示例_extjs

ExtJS4中使用mixins实现多继承示例_extjs

WBOY
WBOYOriginal
2016-05-16 17:10:531184Durchsuche

在ExtJS4中使用mixins来实现多继承。具体例子代码如下:

复制代码 代码如下:

(function(){
Ext.onReady(function(){
Ext.define('say',{
canSay:function(){
alert("hello");
}
});
Ext.define('eat',{
caneat:function(){
alert("eating");
}
});
Ext.define("user",{
mixins:{
csay:'say',
ceat:'eat'
}
});
var ss = Ext.create("user",{});
ss.caneat();
ss.canSay();
});
})();

需要注意的是mixins和extend的区别,extend只能实现单继承,因为extend后面跟的参数只能是一个String类型的字符串,不能使用逗号等将文件隔开。

而在mixins中可以加载多个类,来实现多继承的效果。
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn