I am writing this here just to write down some problems I encountered when doing js, as a note. I didn’t expect to be “criticized” by hax, but it makes some sense. After all, this content is not painful
Generally, we use function literals to name a simple function in JS.
This is also legal in IE or Mozilla (there is a definition of function literal in the ECMA standard).
But there is another simpler naming method in IE that can simplify our code:
http://blog.never-online.net
This does not report a syntax error in Mozilla, but throws an exception, and the operator is illegal:
The following code captures the exception thrown by Mozilla and prints it out
http://blog.never-online.net
The exception content is:
[Exception... "Illegal operation on WrappedNative prototype object" nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame :: file:///C:/Documents and Settings/Administrator/Local Settings/Temp/non4A.htm :: :: line 22" data: no]
I don’t know yet whether it can be set in Mozilla’s config. In short, you should pay attention when writing code.
I searched for the getElementById 0x8057000c keyword on Google, and there are still many similar situations. For example
http://groups.google.co.uk/group/comp.lang.javascript/browse_thread/thread/65a1a23f5dd7c9ad/d264d04d9d768b28?tvc=2#d264d04d9d768b28
Nothing better The solution, but it can be worked around, is to write like this
<script> <BR>var func=function(s){window.alert(s)}; <BR>func("never-online") <BR></script><script> <BR>var $=document.getElementById; <BR>alert($("demo").innerHTML); <BR></script> because js can dynamically add attributes and methods to objects, the above example is The test can pass in both ie and moz. <script> <BR>var $=document.getElementById; <BR>try { <BR>alert($("demo").innerHTML); <BR>} catch(ex) { document.write(ex)} <BR></script><script> <BR>document.$ = document.getElementById; <BR>alert(document.$("foo").innerHTML); <BR></script>