Guest User

Untitled

a guest
Jan 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. /**
  2. * Created with JetBrains PhpStorm.
  3. * User: scotty
  4. * Date: 28/08/2013
  5. * Time: 19:39
  6. */
  7. ;(function(global){
  8. "use strict";
  9.  
  10. var M = function() {
  11.  
  12. // Constructor. arguments are passed
  13. // from Module() call. this refers to m.
  14. function init() {
  15. meth_priv2();
  16. m.meth_pub2();
  17. }
  18.  
  19. // Empty object, to be populated with
  20. // public properties and methods.
  21. var m = {};
  22.  
  23. // Private properties. define using var x.
  24. // closure keeps them private.
  25. var prop_priv = "private property";
  26.  
  27. // public properties. define using m.x.
  28. m.prop_pub = "public property";
  29.  
  30. // private methods. define as var x = function() {}
  31. // closure keeps them private.
  32. var meth_priv = function() {
  33. console.log(prop_priv);
  34. console.log(m.prop_pub);
  35. };
  36.  
  37. var meth_priv2 = function() {
  38.  
  39. // access another priv method
  40. meth_priv();
  41.  
  42. // access a pub method
  43. m.meth_pub();
  44. };
  45.  
  46. // public methods. define as m.x = function() {}
  47. // private props/methods accessed via x.
  48. // public props/methods accessed via m.x
  49. m.meth_pub = function() {
  50. console.log(prop_priv);
  51. console.log(m.prop_pub);
  52. };
  53.  
  54. m.meth_pub2 = function() {
  55.  
  56. // access a priv method
  57. meth_priv();
  58.  
  59. // access another pub method
  60. m.meth_pub();
  61. };
  62.  
  63. // call the constructor
  64. init.apply(m, arguments);
  65. return m;
  66. };
  67.  
  68. // determine correct export method depending upon
  69. // environment that this script was loaded in:
  70. if (typeof module != 'undefined' && module.exports) {
  71. module.exports = M; // Node / CommonJS...
  72. } else if (typeof define === 'function' && define.amd) {
  73. define('Module', [], M); // or RequireJS / AMD...
  74. } else {
  75. global.Module = M; // or browser
  76. }
  77.  
  78. })(this.window || global);
Add Comment
Please, Sign In to add comment