Skip to content

Instantly share code, notes, and snippets.

@ZeeAgency
Forked from 140bytes/LICENSE.txt
Created June 23, 2011 23:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ZeeAgency/1043870 to your computer and use it in GitHub Desktop.
Save ZeeAgency/1043870 to your computer and use it in GitHub Desktop.
dependency management
(function(
a, // placeholder for stored modules
b, // placeholder for module's dependencies
c // placeholder for iterator
) {
return function(
e, // @string : module's name
f, // @array : module's dependency list
g // @object || @function : module's content
) {
b = [];
if(g && g.constructor && g.apply) { // if the module content is a function
for(c in f) { // then we iterate over the dependency list
b[c] = a[f[c]]; // push the stored dependency
}
a[e] = g.apply(this, b); // store the new module with its dependencies as arguments
} else {
a[e] = g; // else if the module content is a litteral, we store it
}
};
})({});
(function(b,e,c){return function(f,d,a){d=[];if(a&&a.constructor&&a.apply){for(c in d)e[c]=b[d[c]];b[f]=a.apply(this,e)}else b[f]=a}})({});
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "define",
"description": "dependency management requirejs like",
"keywords": [
"define",
"dependency",
"module",
"require"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>bar</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
// Usage
var define = (function(a,b,c){return function(e,f,g){b=[];if(g&&g.constructor&&g.apply){for(c in f)b[c]=a[f[c]];a[e]=g.apply(this,b)}else a[e]=g}})({});
define('module-1', [], {foo: 'bar'});
define('module-2', ['module-1'], function(module1) {
document.getElementById('ret').innerHTML = module1.foo;
});
</script>
@jimmywarting
Copy link

You could use =>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment