extjs mixin example

//1. Define our simple mixin class called HasCamera with a single //method called takePhoto:
Ext.define('HasCamera', {
takePhoto: function(){
alert('Say Cheese! .... Click!');
}
});
//2. Define a skeleton class and use the mixins configuration option //to apply our HasCamera mixin to our Cookbook.Smartphone class.
Ext.define('Cookbook.Smartphone', {
mixins: {
camera: 'HasCamera'
}
});
//3. We can now call our mixin's takePhoto method as part of the 
// Smartphone's class within a useCamera method:
Ext.define('Cookbook.Smartphone', {
mixins: {
camera: 'HasCamera'
},
useCamera: function(){
this.takePhoto();
}
});
//4. Instantiate the Smartphone class and call the useCamera method:
var smartphone = Ext.create('Cookbook.Smartphone');
smartphone.useCamera(); // alerts 'Say Cheese! .... Click!'

你可能感兴趣的:(JavaScript,ExtJs,mixin)