in es5 we use constructor function
function Person(name,gender){
var initial =; // we use var key word to make variable private
function getNameWithInitial(){ // this is the private method to get name with initial
console.log(this);
initial = this.gender ===male?Mr. :Mrs. ;
return initial + this.name;
}
this.name = name;
this.gender = gender;
this.getName = function(){
return getNameWithInitial.call(this);
}
}
var manas = new Person(Manas,male);
console.log(manas.getName());
My question is how to declare a private variable and private method in es6 class