Jump to content

Cannot have " this" in prototype


Recommended Posts


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

_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 ={

var cloud = new _obj(parameters)
cloud.def(400,900) //DON'T WORKS


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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