Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CommonJS module loader in Firefox

CommonJS module loader in Firefox

Lightning talk at Firefox work week about add-on SDK loader that is planned to land to Firefox soon.

gozala

May 04, 2012
Tweet

More Decks by gozala

Other Decks in Programming

Transcript

  1. let { doStuff } = require('other/libs') exports.stuff = function(options) {

    // do some stuff... } You can require other libs and export your stuff Each module is loaded in it’s own sandbox You can expose stuff by putting it into exports
  2. let loader = Loader({ // provide path for modules baseURI:

    'resource:///modules/', // provide module global bindings globals: { console: { log: dump } }, // provide set of built-in modules modules: { 'dev-tools/gcli': Cu.import('resource:///modules/gcli.jsm'), 'net/utils': Cu.import('resource:///modules/NetUtil.jsm'), } }) Creating a loader is pretty simple