duwei
小狐狸
小狐狸
  • UID5847
  • 注册日期2005-05-10
  • 最后登录2013-11-22
  • 发帖数9
  • 经验12枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
阅读:2820回复:0

组件注册不上, 代码有错误吗? 谢谢!

楼主#
更多 发布于:2008-03-22 05:16
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.
游客

返回顶部