Jump to content

Are you using JavaScript ES 6?


PhaserEditor2D
 Share

Recommended Posts

Hi,

In Phaser Editor we are about to replace the current JavaScript intelli-sense engine by the one used by VSCode (Salsa).

Salsa works well for JavaScript ES6 but for ES3 it lacks important features like type inference of prototype inheritance. But, is not the time to forget ES3 and start coding in ES6? If you want to target older browsers you can compile the ES6 code into ES3 just before to publish the game (as probably you are doing now to create the .min files), but in the meantime, you can code and test in ES6.

ES6 is very nice for Phaser games development, especially when you want to create custom objects, like sprites, just compare these codes:

 

ES6:

class MySprite extends Phaser.Sprite {
  
  constructor(game) {
    super(game, "dude");
  }

  update() {
     // custom behavior
  }
}

 

ES3:

MySprite = function (game) {
  Phaser.Sprite.call(this, game, "dude");
}

MySprite.prototype = Object.create(Phaser.Sprite.prototype);
MySprite.prototype.constructor = MySprite;

MySprite.prototyte.update = function () {
  // custom behavior
}

 

The ES6 code is way more clear and simple. Actually, the ES3 way is so confusing that probably I wrote it wrong ;-)

 

Link to comment
Share on other sites

  • PhaserEditor2D changed the title to Are you using JavaScript ES 6?
2 hours ago, 8Observer8 said:

You can use ES6 features by using TypeScript. It will be compiled to ES3 or ES5. VSCode is friendly with TypeScript. Phaser has build in support for TypeScript.

I've used TypeScript a little and while at first the typing was a great way to catch edge cases and enforce stricter code, the actual code became a bit of a mess to maintain, having to type evvvvvvverything. I think it's a bit excessive. I haven't looked at something like FlowJS, so dunno if that reduces the code smell but it seems quite popular ATM.

 

2 hours ago, Bobomite said:

No one I know uses ES6 for any job.  No one bothers learning it at all.  So I also don't use it in hobby game coding.  Just my take.

Conversely, almost all the JS devs I know use ES6, and that seems to reflect in the broad trend with devs generally (see something like https://stateofjs.com/2016/flavors/ for last years trends; very interesting to see how Coffeescript has effectively died a death after briefly being championed for a while) TBH there's not a lot to 'learn' anyway, it's just an extension to the existing syntax to introduce saner & smarter options to how you code your applications or games. The "class" sytax alone is enough reason to start using it - the old way of doing JS classes is insanity. 

Equally, it's ridiculously easy to set up something like BabelJS or Browserify to convert your ES6 into whatever JS version you wish to support - TBH at this point, there's no good reason for any JS Dev not to learn ES6. Hobby coding is the perfect environment to learn these things too - no project deadlines or management pressure to interfere with a chance to properly upskill. I'd recommend it, because those not 'bothering' may find themselves struggling to stay relevant or hirible; not trying to sound harsh looking at the state of recruitment there's an increasing focus on devs familiar or experienced with ES5 => ES6 :-)

Link to comment
Share on other sites

I wouldn't do anything but very basic stuff without any kind of transpiler anymore, and I would definitely not do anything with phaser without it. Thanks to node and transpilers we don't have to think about browser compatibility or being stuck with aged standards. ES5 is valid ES6 and Typescript so there is nothing new to learn, just new possibilities. With babel or typescript you can focus on your codebase without any worries about deploying the code. Node and projects such as babel has (partly) liberated us from browser hell :-) The same goes for+ css and transpilers such as sass.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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