问题描述
当我遇到一个有趣的现象在Firefox,文件
声称支持时,我正在迭代文档
的属性属性 domConfig
虽然,但是当我尝试检索属性时,我会收到一个例外:以下显示的行为,Chrome和IE都是一致的(我没有检查过Opera)说, domConfig
不是窗口的属性,但Firefox声称它是但是无法检索它(从粘贴到URL字段,因为我可以
/ *在FF中为true,在其他浏览器中为false * /
javascript :alert(文件中的domConfig)
/ *在FF中的异常,其他浏览器中的'undefined'* /
javascript:alert(typeof(document.domConfig))
这里发生了什么?
Pointy的权利, domConfig
在界面中公开(DOM Level 3 Core - 在Mozilla的来源中,它被称为),但是(见 nsDocument :: GetDomConfig()
)。 typeof
首先得到值,然后确定它的类型(而不是从接口定义),所以这并不奇怪 typeof document.domConfig
抛出异常。
至于为什么这样做,没有任何讨论,所以我们只能猜到。
我的猜测是,为了规范Mozilla旨在实现它是有意义的,以完成(冻结Mozilla的术语)接口,以便它们可以从二进制代码使用,而不需要进一步修改后,界面的新属性/方法实施了而且这似乎并不重要。
如果您有兴趣从开发者那里听到,您可以在或mozilla.dev.platform。
I was iterating over properties of document
when I ran into an interesting phenomena in Firefox, document
claims to support the property domConfig
although MDC says it isn't implemented but when I try to retrieve the property I get an exception:
The following shows the behaviour, both Chrome and IE are consistent (I haven't checked Opera) in saying that domConfig
is not a property of window but Firefox claims it is but can't retrieve it (copy paste into URL field since I can't get markdown to give a link).
/* true in FF, false in other browsers */
javascript:alert("domConfig" in document)
/* exception in FF, 'undefined' in other browsers */
javascript:alert(typeof(document.domConfig))
What's going on here?
Pointy's right, domConfig
is exposed in an interface (DOM Level 3 Core Document - in Mozilla's source it's called nsIDOM3Document), but is not implemented (see nsDocument::GetDomConfig()
). typeof
works by first getting the value, then determining its type (and not from the interface definition), so it's not surprising typeof document.domConfig
throws an exception.
As for why it's been done this way, the bug this code was added in doesn't have any discussion about that, so we can only guess.
My guess is that for specifications Mozilla intended to implement it made sense to finalize ("freeze" in Mozilla's terms) the interfaces, so that they could be used from binary code without further modifications after new properties/methods of the interface got implemented. And it didn't seem to matter much one way or another.
If you're interested in hearing from the developers, you could ask in mozilla.dev.tech.dom or mozilla.dev.platform.
这篇关于Firefox上的document.domConfig有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!