Beware trailing comma in JavaScript prototypes

I spent more time than I care to admit tracking down this one, perhaps this post will save someone else the trouble...

When defining a number of functions in a prototype in JavaScript, do not include a trailing comma after the last function:

MyType.prototype = {
foo : function() {
// ...
},

bar : function() {
//...
}, //<- fails in IE!
}

What was especially tricky about tracking this problem down was that FireFox works with or without the trailing comma, so it only fails in IE!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Captcha
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 11 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.