Javascript - 引用实例化对象

时间:2015-07-06 06:28:13

标签: javascript function class this

假设我有一个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对象。

1 个答案:

答案 0 :(得分:3)

bind函数:

Event.observe(window, "resize", (function(){
    this.stolen = true;
}).bind(this));
相关问题