Reserved JavaScript Words in Safari
I ran into a problem today where the RIA I’m building works for all browsers except Safari – specifically Safari 4, not sure about 3.
The error happens when a certain page loads, and all I’m greeted with in Safar is `SyntaxError: Parser Error`. Nice.
After a little debugging and Googling, I realized that one of the objects I had setup used a property that was a JavaScript reserved word. For whatever reason, SquirrelFish (Safari 4’s JS engine) was the only engine to throw this error.
So something like this would work in all browsers except Safari:
// Parse Error in Safari 4
var myObject = {
enum: 1,
class: 'foobar',
faz: 'baz'
};
Instead, you need to wrap reserved words around quotation marks.
// Works in Safari 4 now
var myObject = {
'enum': 1,
'class': 'foobar',
faz: 'baz'
};
I’m not sure if SquirrelFish is correct, or the other engines. The inconsistency is a bit annoying though.
