Advertisement
Guest User

Untitled

a guest
May 24th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. /**
  2. * Simple Encapsulation Class template
  3. */
  4. (function (root) {
  5.  
  6. "use strict";
  7.  
  8. /**
  9. * Common object params
  10. * @type {Object}
  11. */
  12. var common = {
  13. publicMethods: ['getName'],
  14. className: 'MyPlugin'
  15. },
  16.  
  17. /**
  18. * Main constructor
  19. * @return {Object} - this handle
  20. */
  21. Protected = function () {
  22.  
  23. this.name = 'MyName';
  24.  
  25. return this;
  26. };
  27.  
  28.  
  29. /**
  30. * Main prototype
  31. * @type {Object}
  32. */
  33. Protected.prototype = {
  34.  
  35. getName: function () {
  36.  
  37. return this.name;
  38. }
  39. };
  40.  
  41. /**
  42. * Encapsulation
  43. * @return {Object} - this handle
  44. */
  45. root[common.className] = function () {
  46.  
  47. function construct(constructor, args) {
  48.  
  49. function Class() {
  50. return constructor.apply(this, args);
  51. }
  52.  
  53. Class.prototype = constructor.prototype;
  54. return new Class();
  55. }
  56.  
  57. var publicly = construct(Protected, arguments),
  58. i,
  59. l = common.publicMethods.length;
  60.  
  61. for (i = 0; i < l; i += 1) {
  62.  
  63. (function () {
  64. var member = common.publicMethods[i];
  65. root[common.className].prototype[member] = function () {
  66. return publicly[member].apply(publicly, arguments);
  67. };
  68. }());
  69. }
  70.  
  71. return this;
  72. };
  73.  
  74. }(this));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement