mituri

[JS] Wzorzec Piaskownica

Apr 19th, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. console.clear();
  2. var cl = function(text){ console.log(text); }
  3.  
  4.  
  5. Sandbox.modules = {};
  6.  
  7. Sandbox.modules.returnNumbers = function(MYAPP) {
  8. MYAPP.return100 = function() {return 100;};
  9. };
  10.  
  11. Sandbox.modules.returnLetters = function(MYAPP) {
  12. MYAPP.returnABC = function() {return "ABC";};
  13. };
  14.  
  15.  
  16. function Sandbox() {
  17.  
  18.  
  19. var args = Array.prototype.slice.call(arguments); //Put the arguments
  20.  
  21. var callback = args.pop(); //The last argument is the callback
  22. var requiredmodules = args; //The remaining arguments are the require
  23.  
  24. for (i=0; i< requiredmodules.length; i++) {
  25. Sandbox.modules[requiredmodules[i]](this);
  26. }
  27.  
  28. callback(this);
  29.  
  30. }
  31.  
  32.  
  33.  
  34. //Finally here is an example of usage
  35.  
  36. new Sandbox('returnNumbers', 'returnLetters', function (MYAPP) {
  37.  
  38. console.log(MYAPP.return100());
  39. console.log(MYAPP.returnABC());
  40. });
Advertisement
Add Comment
Please, Sign In to add comment