Igor Georgiev

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

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?

Share this post


Link to post
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?

Share this post


Link to post
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 :)

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.