Skip to content

Writing a First-Person-Shooter in JavaScript

March 20, 2007

I just watched an awesome video by Gopal Venkatesan: “Writing Efficient JavaScript”

A lot of the tips I knew about but there were some surprises. Most of the tips would save you a few milliseconds here and there but can really add up if you are doing things with timers or are looping. The most dramatic example was the difference in performance between using DOM methods and  innerHTML . This has been documented elsewhere, particularly at Quirksmode.
Here’s my summary of the presentation:

1. Core JavaScript
using primitive objects
accessing properties and methods
caching function pointers
don’t use eval
don’t use Function constructor
don’t pass function as a string to setTimeout
don’t use with statement
avoid global variables
avoid try/catch in loops
new Array(size) vs pushing

2. JavaScript and DOM
cache intermediate object properties helps in IE/Opera
DOM elements vs innerHTML, cloneNode vs createNode?
minimize reflows
even property access causes reflows? cache offsetWidth\offsetHeight
removing from parent, appending then readding. when changin styles
event handling
utilize event bubbling to save memory, good naming conventions helps


From → JavaScript

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: