How to declare public method and private method in JavaScript

javascript

Solution

No, this is not true. The inner function (`pri`) is a function, not a method. Although the difference is negligible in javascript (since every function can be used as a method and vice versa), you still can't call it as `this.pri()`, which would be possible with true private methods.

As a side note, despite its Java-alike syntax, Javascript, especially its object model, is significantly different from Java/C++/C#. In particular, such concepts as class and encapsulation don't exist in Javascript.

Problem

I am wondering if I need public method, I need to use this ``` var TestClass = function() { this.pub = function() { blahblah; }; ``` If need private method(inner method), I need to use ``` var TestClass = function() { var pri = function() { blahblah; }; ``` Is this true?

Original source