Private method access viewing closure
Closure virw
by Rijo R
JavaScript
var Pizza = function() {
var crust = 'thin'; // private method
var toppings = 3;
var getToppings = function() { // private method
return toppings;
};
var tmp = {};
tmp.getToppings = getToppings; //public method used to assign the tooppings value assosciated with getToppings function
return tmp;
};
var pizzaA = new Pizza();
console.dir(pizzaA);
console.log(pizzaA.getToppings()); // access the private method and return that value from the closure