Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

[SOLVED] When using ES6 'new ClassName()' I cannot see required params


Igor Georgiev
 Share

Recommended Posts

Hello guys :)

I have recently started doing my projects in ES6 and I am wondering the following.

//Player.js
class Player extends Phaser.Image
{
    constructor(game, x, y, sheet, key)
    {
        super(game, x, y, sheet, key);

    }

}
export default Player;

//GameState.js

import Player from 'views/Player';

class GameState extends Phaser.State {

	create() 
    {
      this.player = new Player();  // Cannot see required parameters
      
      //If I call it like that
      this.player = Player.constructor() // I can see them - obviously
	
	}

}

export default GameState;

Should I just initialize the new Player and then just call the constructor so I can actually create what I need?

Link to comment
Share on other sites

It sounds like you're describing a problem with the intellisense in your editor. Your question is: my editor is not showing the constructor's parameters correctly in a tooltip?

That code "this.player = Player.constructor();" won't really do what you want and doesn't make sense. You really do want that first one, "this.player = new Player(this.game, 320, 240, 'sprites', 'player0');" (or whatever). What editor are you using?

Link to comment
Share on other sites

18 minutes ago, drhayes said:

It sounds like you're describing a problem with the intellisense in your editor. Your question is: my editor is not showing the constructor's parameters correctly in a tooltip?

That code "this.player = Player.constructor();" won't really do what you want and doesn't make sense. You really do want that first one, "this.player = new Player(this.game, 320, 240, 'sprites', 'player0');" (or whatever). What editor are you using?

After 2 hours of struggling, I found the problem, the editor - in my case Webstorm - did not recognise the path of the import correctly. When I used:

import Player from "../views/Player.js";

It worked like a charm and thank you for the pointers. :)

The point you made about the Player.constructor(), I used only to make a point that the autocomplete displayed the params correctly :)

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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