javascript - 这个对象的类型是什么?它在哪里记录?

标签 javascript xul xpcom

我没有找到这个“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/

相关文章:

javascript - 除了绑定(bind)之外,任何其他解决方案都可以解决 promise 中的上下文问题

javascript - 使用 isoWeekday() 从星期一开始一周

javascript - jPicker 在重置按钮上重置背景颜色以及我如何一次打开单个 jPicker 对话框?

javascript - 如何调试 Firefox 扩展

javascript - 我们如何识别唯一的 nsHTTPChannel?

c++ - C++ XPCOM 组件的测试驱动开发?

javascript - 如何取消for循环内的所有ajax请求

firefox-addon - 如何使用 xpidl (header.py, typelib.py)

javascript - 为什么 ChromeWorker 抛出 "Components is not defined"?

javascript - XPCOM C++多线程和javascript回调