Guest User

Untitled

a guest
Apr 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. function define(name, deps, implementation) {
  2. define.modules = define.modules || {};
  3.  
  4. const depsArray = deps.map(name => define.modules[name]);
  5. define.modules[name] = implementation.apply(implementation, depsArray);
  6. }
  7.  
  8. function require(name) {
  9. return define.modules[name];
  10. }
  11.  
  12. define("bar",[], function(){
  13. function hello(who) {
  14. return "Hello to " + who;
  15. }
  16.  
  17. return {
  18. hello: hello
  19. };
  20. });
  21.  
  22. define("foo",["bar"], function(bar){
  23. var hungry = "John from bar";
  24.  
  25. function foo() {
  26. console.log( bar.hello( hungry ).toUpperCase() );
  27. }
  28.  
  29. return {
  30. foo: foo
  31. };
  32. });
  33.  
  34. var bar = require( "bar" );
  35. var foo = require( "foo" );
  36.  
  37. console.log(
  38. bar.hello( "John" )
  39. ); // Hello to John.
  40.  
  41. foo.awesome(); // HELLO TO JOHN FROM BAR.
Add Comment
Please, Sign In to add comment