Skip to content

Instantly share code, notes, and snippets.

@jrburke
Created October 4, 2011 21:26
Show Gist options
  • Select an option

  • Save jrburke/1262861 to your computer and use it in GitHub Desktop.

Select an option

Save jrburke/1262861 to your computer and use it in GitHub Desktop.

Revisions

  1. jrburke revised this gist Oct 7, 2011. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,9 @@
    (function (define) {
    //The 'id' is optional, but recommended if this is
    //a popular web library that is used mostly in
    //non-AMD/Node environments.
    //non-AMD/Node environments. However, if want
    //to make an anonymous module, remove the 'id'
    //below, and remove the id use in the define shim.
    define('id', function (require) {
    //If have dependencies, get them here
    var a = require('a');
    @@ -20,7 +22,7 @@
    //Create a global function. Only works if
    //the code does not have dependencies, or
    //dependencies fit the call pattern below.
    window.myGlobal = factory(function(value) {
    window[id] = factory(function(value) {
    return window[value];
    });
    }
    @@ -35,7 +37,9 @@
    (function (define) {
    //The 'id' is optional, but recommended if this is
    //a popular web library that is used mostly in
    //non-AMD/Node environments.
    //non-AMD/Node environments. However, if want
    //to make an anonymous module, remove the 'id'
    //below, and remove the id use in the define shim.
    define('id', function (require, exports) {
    //If have dependencies, get them here
    var a = require('a');
    @@ -53,6 +57,6 @@
    //dependencies fit the call pattern below.
    factory(function(value) {
    return window[value];
    }, (window.myGlobal = {}));
    }, (window[id] = {}));
    }
    }));
  2. jrburke revised this gist Oct 7, 2011. 1 changed file with 34 additions and 0 deletions.
    34 changes: 34 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    /**
    * First, better, "set exports/return" option
    */
    (function (define) {
    //The 'id' is optional, but recommended if this is
    //a popular web library that is used mostly in
    @@ -22,3 +25,34 @@
    });
    }
    }));


    /**
    * exports object based version, if need to make a
    * circular dependency or need compatibility with
    * commonjs-like environments that are not Node.
    */
    (function (define) {
    //The 'id' is optional, but recommended if this is
    //a popular web library that is used mostly in
    //non-AMD/Node environments.
    define('id', function (require, exports) {
    //If have dependencies, get them here
    var a = require('a');

    //Attach properties to exports.
    exports.name = value;
    });
    }(typeof define === 'function' && define.amd ? define : function (id, factory) {
    if (typeof exports !== 'undefined') {
    //commonjs
    factory(require, exports);
    } else {
    //Create a global function. Only works if
    //the code does not have dependencies, or
    //dependencies fit the call pattern below.
    factory(function(value) {
    return window[value];
    }, (window.myGlobal = {}));
    }
    }));
  3. jrburke revised this gist Oct 4, 2011. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    (function (define) {
    //The 'id' is optional, but recommended if this is
    //a popular web library that is used mostly in
    //non-AMD/Node environments.
    define('id', function (require) {
    //If have dependencies, get them here
    var a = require('a');
  4. jrburke revised this gist Oct 4, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,8 @@
    module.exports = factory(require);
    } else {
    //Create a global function. Only works if
    //the code does not have dependencies.
    //the code does not have dependencies, or
    //dependencies fit the call pattern below.
    window.myGlobal = factory(function(value) {
    return window[value];
    });
  5. jrburke created this gist Oct 4, 2011.
    20 changes: 20 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    (function (define) {
    define('id', function (require) {
    //If have dependencies, get them here
    var a = require('a');

    //Return the module definition.
    return value;
    });
    }(typeof define === 'function' && define.amd ? define : function (id, factory) {
    if (typeof module !== 'undefined' && module.exports) {
    //Node
    module.exports = factory(require);
    } else {
    //Create a global function. Only works if
    //the code does not have dependencies.
    window.myGlobal = factory(function(value) {
    return window[value];
    });
    }
    }));