如何打电话给私人&命名空间内的公共函数

时间:2015-08-17 20:33:08

标签: javascript

我有一个名称空间,它具有很少的私有和公共功能。如何从另一个公共函数(在同一命名空间内)调用它们?

var myns = (function () {    
  var module = {};   

  function private_F1() {        
  }

  function private_F2() {

  }    

  // public
  module.public_doSomething = function () {        
  };

  module.Init= function () {
    // Why cant i call functions inside the same namespace using "this"

    this.private_F1(); //does not work with "this" keyword

    private_F1(); //worked  without "this" keyword

    this.public_doSomething() //does not work with "this" keyword

    public_doSomething //does not work without "this" keyword

    myns.public_doSomething() //worked with namespace
  };

  return module;

})();

0 个答案:

没有答案