Tuesday, July 17, 2007

Fritz Onion: Beware trailing comma in JavaScript prototypes

Itt van, de rovid ugyhogy be is masolom:

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

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

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

function: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!