Mixins are used in ExtJS4 to implement multiple inheritance examples

  • 2020-03-30 00:40:57
  • OfStack

Mixins are used in ExtJS4 to implement multiple inheritance. The specific example code is as follows:

 
(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(); 
}); 
})(); 

Note the difference between mixins and extend, which can only implement single inheritance, because extend can only be followed by a String of type arguments, not separated from a file by commas, etc.

In mixins, multiple classes can be loaded to achieve the effect of multiple inheritance.


Related articles: