0

I have the following code

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);
};

As you can see, the keyword this refers to the sprite, howerver i want to refer to the object so i can get the properties :/ Thank you

Özgür Ersil
  • 6,909
  • 3
  • 19
  • 29
Namrouch
  • 3
  • 2

1 Answers1

0

You can use bind:

}.bind(this), true);  //this is last line of your listener
Engineer
  • 47,849
  • 12
  • 88
  • 91