JavaScript, the new parts
January 6th, 2018As things were quiet over the Christmas period I decided to catch up with some of the recent additions to JavaScript. Rather than just putting together a few little “Hello World” snippets of code to play with the new features, I decided I wanted to build something useful. Well, sort of useful…
I decided the world needed another Break Out clone!
Breakanoid
Breakanoid is a retro-style brick breaker game with some awesome chip tune music and sound effects; all written in client-side JavaScript using as many of the new features as I could sensibly include.
Some of the things I experimented with in this code include:
- JavaScript Modules
- No semicolons (controversial, for sure… oh, and no empty parens when calling constructors)
- The Spread and Rest operators
- Expression bodies and Statement bodies rather than anonymous functions
- Classes instead of functions and prototypes
- Sets and Maps instead of arrays and objects
- The HTML audio element
As everything is loaded through a module script tag this means that, currently, Breakanoid will only work in a few browsers, which, surprisingly, doesn’t include FireFox. The latest version of Chrome is a safe bet. Apart from the sound, it works reasonably well on mobile devices, too.
It’s not quite finished (there’s only one playable level at the moment) but it is quite fun. The code isn’t optimised, so there is the occasional slowdown when garbage collection kicks in, but I have a plan for that and I’ll be improving the code in the future.
While I wrote the code, the sounds, music, and the fonts are from various sources, which can be found in the credits.
So go and play the game, or poke around in the code. Let me know what you think below.