Extend?

Hi, I watched a tutorial and it showed that to use a function i had to, at the top of the js file, put

extend:
        {
          functionName: functionName,
        }

but it was not explained. What actually is this, is it like forward declaration?

It’s for adding adding properties to a scene created with an object config.

mmm ok, I think i might understand, so if i have a function declared in extend: {} I can refer to it using this. ?

I am trying to create a player function, which I think i need to use this extend for (dont have the function working yet, but is this how it should be done? The class I am trying to use is below

createPlayer = function(x, y, key, game)
{
    this.player = this.physics.add.sprite(game, x, y, key);    
    this.health = 100;
    return player;
}

and i can call it using

player = new createPlayer(200, 500, 'player', game);

Would that be right?

Yes, if you’re creating a scene from an object config, everything in extend is copied onto the new scene.

function create() {
  this.player = this.createPlayer(200, 500, 'player');
}

function createPlayer(x, y, key) {
  const player = this.physics.add.sprite(x, y, key);
  player.health = 100;

  return player;
}