mituri

[JS] Wzorzec Piaskownica II

Apr 19th, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. console.clear();
  2. var cl = function(text){ console.log(text); }
  3.  
  4. Sandbox.modules = {};
  5.  
  6. Sandbox.modules.dam = function(box){
  7. box.getElement1 = function(){};
  8. box.getElement2 = function(){};
  9. box.getElement3 = function(){};
  10. box.showDamEvent = function(){
  11. console.log('inside dam');
  12. }
  13. };
  14.  
  15. Sandbox.modules.event = function(box){
  16. box.constructor.prototype.m = 'mmm';
  17. box.attachEvent = function(){};
  18. box.dettachEvent = function(){};
  19. box.showEvent = function(){ console.log('amfa techno');};
  20. }
  21.  
  22. function Sandbox(){
  23. var args = Array.prototype.slice.call(arguments),
  24. callback = args.pop(),
  25. i,
  26. modules = (args[0] && typeof args[0] === 'string') ? args: args[0];
  27.  
  28. if (!(this instanceof Sandbox)){
  29. return new Sandbox(modules, callback);
  30. }
  31.  
  32. this.a = 1;
  33. this.b = 2;
  34.  
  35. if (!modules || modules === '*'){
  36. modules = [];
  37. for(i in Sandbox.modules) {
  38. if (Sandbox.modules.hasOwnProperty(i)){
  39. modules.push(i);
  40. }
  41. }
  42. }
  43.  
  44. for (i = 0; i < modules.length; i += 1){
  45. Sandbox.modules[modules[i]](this);
  46. }
  47.  
  48. callback(this);
  49. }
  50.  
  51. Sandbox.prototype = {
  52. name: "moja apka",
  53. version: '1.0'
  54. };
  55.  
  56. Sandbox(
  57. ['dam','event'],
  58. function(box){
  59. box.showEvent();
  60. box.showDamEvent();
  61. }
  62. );
Advertisement
Add Comment
Please, Sign In to add comment