Ext.bind() 方法

var cat = {
sound: 'miaow',
speak: function(){
alert(this.sound);
}
};
var dog = {
sound: 'woof',
speak: function(){
alert(this.sound);
}
};
cat.speak(); // alerts 'miaow'
dog.speak(); // alerts 'woof'
Ext.bind(dog.speak, cat)(); // alerts 'miaow'


How it works:
The Ext.bind method creates a wrapper function for the speak method that will force it
to have its scope set to the object that is passed in, overriding the default scope value. This
new function can be executed immediately (as our example did) or stored in a variable to be
executed at a later point.

你可能感兴趣的:(ExtJs)