|
阅读:3064回复:0
组件注册不上, 代码有错误吗? 谢谢!Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function HelloWorld(){};
HelloWorld.prototype = {
classDescription: "My Hello World JavaScript XPCOM Component",
classID: Components.ID("{f7c44761-5a25-44b4-8d05-d0ce44465807}"),
contractID: "@dietrich.ganx4.com/helloworld;1",
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIHelloWorld]),
hello: function(){
return "Hello, World!";
}
}
var components = [HelloWorld];
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule(components);
}这是Mozilla wiki上的How to Build an XPCOM Component in Javascript主题里的一个例子. 两个文件HelloWorld.js和HelloWorld.xpt, 以上代码是HelloWorld.js中的内容, 两个文件存放在了扩展的chrome/components文件夹内, 但XPT注册上了, 接口用XPCOMViewer能够看到, 但为什么组件注册不上呢? var myComponent = Components.classes['@dietrich.ganx4.com/helloworld;1']
.createInstance(Components.interfaces.nsIHelloWorld);
上面是用来被XUL调用的js代码, 异常报告@dietrich.ganx4.com/helloworld;1类未定义! 我用的是Firefox 3 Beta 4. |
|