I have read in a post JavaScript private methods that we can "simulate" private method in javascript.
function Restaurant(price)
{
var myPrivateVar;
this.price = price;
var private_stuff = function() // Only visible inside Restaurant()
{
myPrivateVar = "I can set this here!";
}
this.toto = function() {
private_stuff();
// do sthg
}
}
When I try to call price member in private_stuff method, it doesn't work :
var private_stuff = function() // Only visible inside Restaurant()
{
myPrivateVar = "I can set this here!";
alert(this.price); // return undefined !
}
So how to use public properties in a private method in javascript ?