Ext.onReady(function() {
/**
* Date : 2013.05.22
* Desc : Mixins를 설명한다. 이를 통해 다중 상속를 구현할 수 있다.
*/
Ext.define('HasCamera',{
takePhoto : function(){
console.log('Say Cheese! Click!')
}
});
Ext.define('Cookbook.Smartphone',{
mixins : {
camera : 'HasCamera'
},
useCamera : function(){
/***
* 우선 현재 클래스에 takePhoto함수가 있다면
* 실행하고 없다면 mixins에서 참조하고 있는 클래스를
* 찾아 실행한다.
* 현재 클래스의 takePhoto를 삭제하면 아래에서 호출되는
* takePhoto는 mixins에서 참조한 클래스의 함수 일 것 이다.
*/
this.takePhoto();
},
takePhoto: function(){
this.focus();
// mixins으로 접근 시.
this.mixins.camera.takePhoto.call(this);
},
focus: function(){
console.log('Focusing Subject...');
}
});
var smartphone = Ext.create('Cookbook.Smartphone');
smartphone.useCamera();
});
// 출처 : Ext JS4 Web Application Development Cookbook