Home > Web Front-end > JS Tutorial > Javascript-The problem of direct quantity of a function in Mozilla and IE_javascript skills

Javascript-The problem of direct quantity of a function in Mozilla and IE_javascript skills

WBOY
Release: 2016-05-16 19:21:29
Original
1126 people have browsed it

Generally, we use function literals in JS to name a simple function.




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> <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> because js can dynamically add attributes and methods to objects, the above example is The test can be passed in both ie and moz.
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template