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.
本文探讨了JavaScript中对象方法的使用以及如何通过`Ext.bind`方法实现事件绑定,包括直接执行和延迟执行两种场景。
2815

被折叠的 条评论
为什么被折叠?



