Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function define(name, deps, implementation) {
- define.modules = define.modules || {};
- const depsArray = deps.map(name => define.modules[name]);
- define.modules[name] = implementation.apply(implementation, depsArray);
- }
- function require(name) {
- return define.modules[name];
- }
- define("bar",[], function(){
- function hello(who) {
- return "Hello to " + who;
- }
- return {
- hello: hello
- };
- });
- define("foo",["bar"], function(bar){
- var hungry = "John from bar";
- function foo() {
- console.log( bar.hello( hungry ).toUpperCase() );
- }
- return {
- foo: foo
- };
- });
- var bar = require( "bar" );
- var foo = require( "foo" );
- console.log(
- bar.hello( "John" )
- ); // Hello to John.
- foo.awesome(); // HELLO TO JOHN FROM BAR.
Add Comment
Please, Sign In to add comment