Home  >  Article  >  Web Front-end  >  Javascript-Mozilla和IE中的一个函数直接量的问题_javascript技巧

Javascript-Mozilla和IE中的一个函数直接量的问题_javascript技巧

WBOY
WBOYOriginal
2016-05-16 19:21:29996browse

一般情况下,我们在JS中用函数直接量来命名一个简单的函数。



这在IE或者Mozilla中也是合法的(ECMA标准中有函数直接量的定义)。

但是IE中还有另外一种更简单的命名方式可以简化我们的代码:

http://blog.never-online.net



而这在Mozilla中没有报语法错误,而是抛出了一个异常, 操作符非法:
下面代码是捕获Mozilla抛出的异常并打印出来

http://blog.never-online.net



异常内容为:
[Exception... "Illegal operation on WrappedNative prototype object" nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame :: file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/non4A.htm :: :: line 22" data: no]

现在还不知道能不能在Mozilla的config中设置,总之写代码的时候要注意.

我在google上搜索 getElementById 0x8057000c 关键字,还是有很多类似的情况,比如

http://groups.google.co.uk/group/comp.lang.javascript/browse_thread/thread/65a1a23f5dd7c9ad/d264d04d9d768b28?tvc=2#d264d04d9d768b28

没有更好的解决办法,但是可以变通,比这样写




因为js可以动态的给对象增加属性和方法,上面的例子在ie和moz中测试都可以通过. 
Statement:
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