如何使它引用构造函数

时间:2015-06-18 12:38:58

标签: javascript click this

我有以下代码

function perso (image_mere, emplacement_x, emplacement_y, x, y, direction) {
         this.source = image_mere;
         this.sprite = createElement('div');

         // some other properties                       
         this.sprite.addEventListener('click', function() {
         dindong = this;
         (function(dindong) {
            var canvas = document.createElement('canvas'),
            context = canvas.getContext('2d');
            alert(dingdong.image_mere)
         })(dindong);
    }, true);
};

正如你所看到的,关键字this指的是sprite,howerver我想引用该对象,所以我可以得到属性:/ 谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用bind

}.bind(this), true);  //this is last line of your listener
相关问题