开发者

Can I call other methods in other javascript files from my overlay script?

I am writing a Firefox extension. I have setup an overlay for chrome://browser/content/browser.xul and I am handling the on load event. This I have working.

I also have N separate .js files in my extension (specifically in chrome://my-extension/content/js/*.js). Each of t开发者_运维技巧hese .js files implements a common interface.

For example, foo.js might look like this:

var fooThinger = {
  doYouCare: function (e) {
    // ... decide if I care ...
    return cares;
  },
  someOtherStuff: function (e) {
    // ... some other stuff ...
  },
  // ... other methods ...
}

function getThinger() {
  return new fooThinger();
}

What I can do is enumerate all of these .js files in my browser on load handler, which I can do using nsIFile and all that.

What I don't know how to do is call the getThinger() method in each file once I've built up a list of all the files in the directory. Is this possible? If so, how?


I think you would use either https://developer.mozilla.org/en/Components.utils.import or mozIJSSubScriptLoader which is described on the same page. I'm not sure which one is better for your case.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜