Join MDN and developers like you at Mozilla's View Source conference, 12-14 September in Berlin, Germany. Learn more at

XPIDL:Function modifier


Adding the function modifier to an IDL interface allows you to pass a basic function as a parameter instead of an object that implements the required interface.  Any member method invoked on the expected interface will call the function that was passed.


IDL file

[function, scriptable, uuid(13e630b8-2f41-456b-ae26-c30b201c8f99)]
interface ICallback : nsISupports
  boolean go(in PRUint32 data);

[scriptable, uuid(98bf0a93-577d-49dc-a9c4-23c172ebd0df)]
interface IFoo : nsISupports
  void sum(in PRUint32 first, in PRUint32 second, in ICallback aCallback);

C++ implementation

NS_IMETHODIMP IFoo::Sum(PRUint32 first, PRUint32 second, ICallback *aCallback)
  PRBool ret = TRUE;
  nsCOMPtr<ICallback> callback = aCallback;

  callback->Go(first+second, &ret);

  printf("Callback returned: %d", ret);


// Note how the callback object does not need to include define XPCOM goop such as QueryInterface
var callback = function (sum) {
return true;
var foo = Components.classes["XXXXXX"].getService(Components.interfaces.IFoo); foo.sum(1, 2, callback});

Document Tags and Contributors

 Last updated by: Anonymous,