Jump to content

Cannot have " this" in prototype


espace
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...