A collection of bad things about JavaScript, such as buggy language implementation gotchas and quirks, especially in browsers. -- SteveYen - Where's my memory? delves into Internet Explorer's JavaScript implementation (also known as JScript), which '''leaks memory when using closures'''.
- Flash's version of JavaScript, aka ActionScript, is different.
- Laszlo implementation of EcmaScript...
- Documented differences can be found here.
- Laszlo EcmaScript limitations might be same as ActionScript limitations (since Laszlo deploys to Flash runtime)?
- Internet Explorer and Mozilla treat JavaScript '''objects and arrays''' shortcut syntax differently.
- The below code with the extra trailing commas works in Mozilla JavaScript engines (Spider Monkey and Rhino). But it causes an exception in Internet Explorer. Too bad -- it actually made programming easier, not having to mentally treat the last item differently.
- var x = { slot1: 123, slot2: 456, };
- var y = 1, 2, 3, ;
- '''String.split()''' with regular expressions is different in IE and Mozilla/Firefox. Type the following into your browser's URL location bar...
- javascript:"a${b}c".split(/(\$\{[^\}]+\})/g)
- Mozilla/Firefox returns "a,${b},c" -- I prefer this return style.
- IE returns "a,c" -- this seems lossy to me, ignoring the capture parenthesis in the regular expression.
- If you type in "javascript:"a${b}c".split(/\$\{[^\}]+\}/g)", you get "a,c" in both browsers.
- You also can't trust the edge cases of the expression appearing at the start and end of the string or right next to each other.
- The upshot is not to use the parenthesis and test everything. Or, don't use regular expressions.
- Here's a comparison table...
| URL code | Mozilla/Firefox | IE | | javascript:"a${b}c".split(/(\$\{[^\}]+\})/g) | a,${b},c | a,c | | javascript:"a${b}".split(/\$\{[^\}]+\}/g) | a, | a | | javascript:"${b}c".split(/\$\{[^\}]+\}/g) | ,c | c | | javascript:"a${b}${c}d".split(/\$\{[^\}]+\}/g) | a,,d | a,d |
- '''eval() and function differences'''
| URL code | Mozilla/Firefox | IE | | javascript:function(){return 111} | nothing! | nothing! | | javascript:(function(){return 111}) | function () { return 111; } | nothing! | | javascript:eval("function(){return 111;}") | nothing! | nothing! | | javascript:eval("var s=function(){return 111};s") | function () { return 111; } | function(){return 111} |
- String charAt works in IE and Mozilla (str.charAt(index)).
- '''Do not rely on strindex''' array-based-syntax shortcut syntax, which might not work in IE.
- Be wary of using undefined global variables in IE.
DOM Related Quirks- innerHTML doesn't work in IE for TABLE elements, but works for Mozilla/Firefox.
- Other resources
See also: ElegantJavaScript
|
<<Be wary of using undefined global variables in IE Another blog entry from Eric Lippert explains why.>>
Link is broken, but I think this is it:
http://blogs.msdn.com/ericlippert/archive/2006/05/04/590030.aspx