How to private variable using public method

by Rijo R

JavaScript

var Pizza = function() {
	var crust = 'thin'; // private method
  this.hasBacon = true; // public method
  var toppings = 3;
  this.getHasbacon = function() { // public function
  	return this.hasBacon;
  };
  this.getCrust = function(){ // public method
  	return crust;
  };
  var getToppings = function() { // private method
  	return toppings;
  };
};

var PizzaA = new Pizza();
console.dir(PizzaA); // we can't access private method but we can see public method
console.log(PizzaA.getHasbacon()); // access public method
console.log(PizzaA.getCrust()); // i can accrss private varaible using public method
console.log(PizzaA.getToppings()); // we cant use this function