Last active
August 29, 2015 14:05
-
-
Save expalmer/cfbaf085256d5902ce2d to your computer and use it in GitHub Desktop.
Simple Require AMD
This file contains 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 ) { | |
'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