Sign in to follow this  
Fairydhwen

Using Prototype to call a function (method)

Recommended Posts

Hi,

I'm reading this tutorial (2nd part) : http://www.gamefromscratch.com/post/2014/06/24/Adventures-in-Phaser-with-TypeScript-Handling-Keyboard-Input.aspx

in the second exemple, we got something like :

class SimpleGame {

    constructor() {
        this.game = new Phaser.Game(640, 480, Phaser.AUTO, 'content', {
            create: this.create});}

    moveUp(e: KeyboardEvent) {
            this.jetSprite.position.add(0, -1);
    }

    create() {
        this.W.onDown.add(SimpleGame.prototype.moveUp, this);
    }
}

can someone tell me why we need to use SimpleGame.prototype.moveUp to call this method? (and not just this.moveUP ?) 

is this because we are using this context ?

regards,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.