ITeye博客

Ext.bind() 方法

standalone · 2012-11-14 21:54 · javascript · 编程语言 · Markdown


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.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。