How can i call a public method from within a private one when using the javascript Module Pattern?

后端 未结 2 1939
感情败类
感情败类 2021-01-02 08:52

I would like to call a public method from a private one but the property \"this\" refers to the window object.

Please note i am trying to apply the module pattern. Y

2条回答
  •  走了就别回头了
    2021-01-02 09:15

    I understand this is a little bit different from the module pattern, but I think it still offers the same benefits of encapsulation. Public methods are declared as:

    this.methodName = function(){...}
    

    the variable $this is assigned to the current instance (this), so you can use it from within private (or public) methods to access any methods or attributes on that instance.

    Fork:

    http://jsfiddle.net/FNjJq/

提交回复
热议问题