-
-
Save ZeeAgency/1043870 to your computer and use it in GitHub Desktop.
dependency management
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( | |
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 | |
} | |
}; | |
})({}); |
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(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}})({}); |
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
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. |
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
{ | |
"name": "define", | |
"description": "dependency management requirejs like", | |
"keywords": [ | |
"define", | |
"dependency", | |
"module", | |
"require" | |
] | |
} |
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
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could use
=>