espace Posted June 23, 2018 Share Posted June 23, 2018 hi, i reproduce the minimal code to show what not works in my case. In this case, i would assign a new value to this in x and y. it's for the example, i could simply do cloud.x=100. why in this case my prototype don't work ? _obj = function (p) { Phaser.Sprite.call(this, p.g, p.x, p.y, p.image); p.g.add.existing(this) } _obj.prototype = Object.create(Phaser.Sprite.prototype); _obj.prototype.constructor = _obj //change the position of the sprite to x and y _obj.prototype.def = (a, b) => { console.log(this) // show window and not expected _obj ??? why ??? this.x = a this.y = b } var parameters ={ g:game, x:100, y:200, image:"cloud", } var cloud = new _obj(parameters) cloud.def(400,900) //DON'T WORKS Link to comment Share on other sites More sharing options...
tips4design Posted June 23, 2018 Share Posted June 23, 2018 Replace the arrow function (a,b) => {} with an actual (non lexical-bound) function: function (a,b) { } Link to comment Share on other sites More sharing options...
espace Posted June 23, 2018 Author Share Posted June 23, 2018 ok but why ? Link to comment Share on other sites More sharing options...
Recommended Posts