假设我有一个javascript函数如下:
car.prototype = {
this.stolen = "",
initialize: function(){
this.stolen = false;
},
steal: function(){
Event.observe(window, "resize", function(){
this.stolen = true;
});
}
}
在steal
方法中,如何在stolen
方法中引用car
对象的Event.observe()
属性?在上面的代码中,this
方法中的Event.observe()
指的是窗口而不是car
对象。
答案 0 :(得分:3)
你bind函数:
Event.observe(window, "resize", (function(){
this.stolen = true;
}).bind(this));