开发者

firefox code modules components.utils.import

Does anyone know of an example/sample .xpi file that uses Components.utils.import开发者_如何学JAVA to load a custom code module? I cannot get it to work. Basically I cannot get it to work when I package to a .jar file. Is this a limitation to use code modules?

A sample would be really helpful, probably with the code below.

var EXPORTED_SYMBOLS = ["foo", "bar"];

function foo() {
  return "foo";
}

var bar = {
  name : "bar",
  size : 3
};


Has passed some time, but here you have:

// modules/module.jsm file
var EXPORTED_SYMBOLS = ["myUniqueCode"];

// wrap your code
var myUniqueCode = {
    foo : function() {
        return "foo";
    },
    bar : {
        name : "bar",
        size : 3
    }
}

// load module where you need it
Components.utils.import("resource://your_addon_name/module.jsm"); 

// use myUniqueCode.foo()

As @felix-kling recommends:

// add to your chrome.manifest file
resource    your_addon_name     modules/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜