O'Reilly logo

Multiplayer Game Development with HTML5 by Rodrigo Silveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing modular JavaScript

Before the advent of Node.js, given all of JavaScript's infamous restrictions, probably the biggest complaint that it received from developers was the lack of built-in support for a modular development process.

The best practice for modular JavaScript development was creating your components inside a literal object, which, in its own way, behaved somewhat like a namespace. The idea was to create an object in the global scope, then use the named properties inside that object to represent specific namespaces where you would declare your classes, functions, constants, and so on (or at least the JavaScript equivalent).

var packt = packt || {}; packt.math = packt.math || {}; packt.math.Vec2 = function Vec2(x, y) {// … }; var ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required