Creating Your Game’s Structure
The code built so far has been a good way to exercise the canvas capabilities you’ll be using, but it will need to be reorganized to turn it into a useful structure for a game. Now take a step back to look at some of the patterns you want to use putting together the game.
Building Object-Oriented JavaScript
JavaScript is an object-oriented (OO) language. As such, most elements in JavaScript are objects including strings, arrays, functions and, well, objects are objects in the OO sense.
But this doesn’t mean that JavaScript has all the trappings of object-oriented programming (OOP) that you might expect. First, it doesn't have a classical inheritance model. Second, it doesn't have a standard constructor mechanism, relying instead on either constructor functions or object literals.
Instead of classical inheritance, JavaScript implements prototypical inheritance, meaning you can create an object that represents the prototype, or blueprint, for a set of descendant objects that all share the same base functionality
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access