Actually, i can almost guess what causes the problem: It must be some extra commas (And it turned out i was right at this). Check this code:
//work in firefox/chrome/IE9, but not in IE7,8 var me = { name : henry, gender: m, //IE7 doesn't allow this last extra comma } //work in firefox/chrome/IE9, but not in IE7,8 var language = [ 'php', 'java', //IE7 doesn't allow this last extra comma ]
if we remove the last comman in the me object and language array, the code will work in IE7 as well.
I am so used to putting comma at the last item of an array or object because that is what i usually do in PHP array. PHP array also allows you to put extra comma at the last item:
$config = array( 'db' => 'mysql', 'username' => 'username', );
In the above code, the last comma brings so much convenience. If i need to add more config options, i simply add them at the bottom without worrying breaking anything.
Although I know what the reason is, but the problem is, how to find it? My IDE, Zend Studio almost helps me nothing in finding javascript coding problems. It can only remind you to put semicolon. So i turned out to netbean 7. In supporting javascript coding, netbean 7 is much better than Zend Studio(and Eclipse). At least it can warn you last extra comma in object is not supported by IE. But the funny thing is, it won't warn you that last extra comma in array is not supported by IE either!
No matter what, based on my experience so far, there are two headaches when working on big javascript projects. 1.We don't have a good IDE especially for javascript(At least i haven't found out yet). 2.Debugging. Debugging javascript is quite painful due to those misleading error messages.
3 comments:
Hey, Thanks Helped a big deal this is also an IE 9 issue!
I am also getting this error "Message: 'events' is null or not an object"
I have looked for all trailing commas and haven't found one.
Do you have any idea why this is happening
Wahab, I am also having the same issue. I have found that most people say run your code through http://jslint.com/ to make sure you didn't miss anything.
Post a Comment