Created
July 10, 2012 13:19
-
-
Save robharper/3083192 to your computer and use it in GitHub Desktop.
Wrapper code to expose a library module built with almond.js as a module in the global scope (with dependencies)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(context) { | |
// Almond.js here | |
// Library module definitions here | |
if (context.define && context.define.amd) { | |
// AMD - expose myLib to outer AMD loader | |
var almondDefine = define; | |
(function(define, almondDefine, almondRequire) { | |
define(["underscore", "backbone", "jquery"], function(_, Backbone, $) { | |
almondDefine("underscore", function() { return _; }); | |
almondDefine("Backbone", function() { return Backbone; }); | |
almondDefine("jquery", function() { return $; }); | |
return almondRequire("myLib"); | |
}); | |
}(context.define, define, require)); | |
} else { | |
// No AMD loader, expose library as object in context | |
// Tell almond.js where to find our three dependencies | |
define("underscore", function() { return context._; }); | |
define("backbone", function() { return context.Backbone; }); | |
define("jquery", function() { return context.jQuery; }); | |
context.MyLib = require("myLib"); | |
} | |
}(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment