Skip to content

Instantly share code, notes, and snippets.

@expalmer
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save expalmer/cfbaf085256d5902ce2d to your computer and use it in GitHub Desktop.
Save expalmer/cfbaf085256d5902ce2d to your computer and use it in GitHub Desktop.
Simple Require AMD
(function( context ) {
'use strict';
var modules = {};
var app = {
getDependencies: function( deps ) {
var ret = [];
var len = deps.length;
var i;
for ( i = 0; i < len; i += 1 ) {
if ( !context[ deps[i] ] ) {
context[ deps[i] ] = {};
}
ret.push( context[deps[i]] );
}
return ret;
}
};
context.define = function( name, deps, cb ) {
var dependencies = [];
var module = {};
dependencies = app.getDependencies( deps );
module = cb.apply(context, dependencies);
context[name] = module;
};
context.require = function( deps, cb ) {
cb.apply( context, app.getDependencies( deps ) );
};
})( this );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment