cachaito
12/3/2014 - 11:09 PM

Module pattern #4

Przykład pochodzi z: http://fedojo.com/pure-javascript-private-and-public-methods/ You can access init() but cannot access prvMethod(). It has only access into MyClass() function scope.

var MyClass = (function() {
  function MyClass() {}
  
  var prvMethod = function() {
    console.log('method');
  };
  
  MyClass.prototype = {
    init: function() {
      console.log('init');
      prvMethod();
    }
  };
  
  return MyClass;
})();

var mc = new MyClass();
mc.init();