Components.interfaces
is a read-only object whose properties are interfaces indexed by their names.
Introduction
Components.interfaces
is a read-only object whose properties implement the nsIJSIID
interface. Each object represents one of the XPCOM interfaces -- that some component or another might or might not implement. It reflects only those interfaces which have been designated in their .idl
description as scriptable
, that is the interfaces which XPConnect is capable of reflecting into JavaScript.
Properties of the Components.interfaces
object are used where XPCOM methods expect a parameter of type nsID
. This includes nsISupports.QueryInterface()
, the optional parameter accepted by nsIJSCID.getService()
, nsIJSCID.createInstance()
when called from JavaScript, and nsIClassInfo.getInterfaces()
.
The properties of the Components.interfaces
object can be enumerated using a for...in loop.
Usage
Accessing an interface object
Properties of the Components.interfaces
object are indexed by interface name. You can retrieve an interface object using:
var iface = Components.interfaces.nsISupportsArray;
This will return you the interface object for the nsISupportsArray
interface.
Accessing constants defined in an interface
Interface descriptions (cf. XPIDL) may not only contain method declarations, but also constants. For example, assume we have the following interface declaration:
interface nsIFoo : nsISupports { const PRUint32 MYFLAG = 5; };
The constant MYFLAG
can then be accessed using
var myFlag = Components.interfaces.nsIFoo.MYFLAG;