HTML and CSS Reference
Each of these three patterns of object creation yield an object that behaves exactly the same, yet the fastest
method ( Obj1 , which uses prototypes) is more than 25 times faster than the slowest method ( Obj2 , using an-
onymous methods assigned to this) in Chrome 18. To run the test, go to http://jsperf.com/object-creation-tests .
Now, on a circa 2010 MacBook Pro, the second method still clocks in at 1.7 million objects per second; so
unless you create lots and lots of objects, the difference isn't going to be particularly noticeable in your typical
game. This speaks to the heart of the problem: Make sure you spend your time optimizing efficiently by first
profiling and then testing your intuition.
Sites such as http://jsperf.com make it easy to set up a test of whatever it is you want to optimize and enable
you to quickly determine if your intuition is correct and if the potential increase in speed is worth the effort.
Debugging on the desktop is okay, but because this topic is about mobile games, there's no substitution for de-
bugging on real hardware. Unfortunately, with the exception of Chrome for Android, there's no built-in way to
debug your page.
If you are on Android with version 4.0 (Ice Cream Sandwich) or newer and have Chrome installed on your
device and the Android SDK installed on your desktop, you can enable Remote Debugging as described in the
Google documentation at http://code.google.com/chrome/mobile/docs/debugging.html .
bug console. This is switched on by going to Settings > Safari > Advanced. Any page you load now shows the
Safari Debug console at the top. If there are errors, they will be noted, and you can click the tab to see some more
details. This is most likely not quite enough when you want to track down some hard-to-debug, platform-spe-
cific issue. The good news is there is a tool called Weinre, which is part of Apache's cordova project that adds
basic remote-debugging capability: https://github.com/apache/incubator-cordova-weinre .
The way Weinre works is by running a Java-based server on a computer that a mobile device can connect
to by including the appropriate script tag. When connected, you can access a limited subset of tabs that behave
similarly to Developer Tools (see Figure 7-17 ).