Skip to content

Commit

Permalink
Merge pull request #6 from tkellen/master
Browse files Browse the repository at this point in the history
add pattern that doesn't require a dependency to returnExports
  • Loading branch information
addyosmani committed Oct 30, 2012
2 parents d3bf788 + a4e7861 commit 42227ef
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion returnExports.js
Expand Up @@ -24,7 +24,7 @@
// AMD. Register as an anonymous module.
define(['b'], factory);
} else {
// Browser globals
// Browser globals (root is window)
root.returnExports = factory(root.b);
}
}(this, function (b) {
Expand All @@ -35,3 +35,26 @@
// can return a function as the exported value.
return {};
}));


// if the module has no dependencies, the above pattern can be simplified to
(function (root, factory) {
if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
} else {
// Browser globals (root is window)
root.returnExports = factory();
}
}(this, function () {

// Just return a value to define the module export.
// This example returns an object, but the module
// can return a function as the exported value.
return {};
}));

0 comments on commit 42227ef

Please sign in to comment.