views:

29

answers:

1

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 these .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?

+1  A: 

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.

MatrixFrog
Looks reasonable. I'll give that a shot (`mozIJSSubScriptLoader`).
jeffamaphone
This worked well.
jeffamaphone