I have code as below.
var Main = function () {
var a, b, c, d;
a = 1;
b = true;
c = undefined;
var _private = function () {
return 'Function with Private acceess';
};
this.getPublic = function () {
return 'Function with Public access';
};
this.getPrivate = function () {
_private();
};
};
var o = new Main();
console.log(o.getPublic());
console.log(o.getPrivate());
In the code above I am trying to access the private method of the Main
object o
through the public method getPrivate()
.
But in the console the result is
undefined
Why is the _private
not returning the desired value?