我没有找到这个“xpcomInterface”的类型,也没有任何具有此名称的类的文档。有什么想法吗?
此片段来自 Mozilla 的网站:
var next = elements.item(i+1);
var xpcomInterface = scroll.boxObject.QueryInterface(
Components.interfaces.nsIScrollBoxObject);
xpcomInterface.ensureElementIsVisible(elements);
--更新
我找到了 boxObject导致 nslBoxObject ,但它没有引用上面使用的任何 QueryInterface
。还有对 xulplanet.com 的引用,但已不存在。
最佳答案
嗯,xpcomInterface
只是变量的名称。
你应该阅读 XPCOM and XPCOM interfaces . QueryInterface()
是所有 XPCOM 对象都必须实现的方法,它使您可以将对象“强制转换”到特定接口(interface):
(...) The function
QueryInterface()
is a function provided by all components which can be used to get a specific interface of that component. This function takes one parameter, the interface that you want to get. (...)
在这个例子中,有一些对象 scroll.boxObject
(update: 这是你发现的 nsIBoxObject
。注意这个again 只是一个接口(interface)(以 nsI
开头))似乎实现了 nsIScrollBoxObject
接口(interface)。通过使用 QueryInterface
,您可以访问这些接口(interface)的方法,例如 ensureElementIsVisible
。
关于javascript - 这个对象的类型是什么?它在哪里记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3781432/