var test = function(id, company){
//public members
this.id = id;
this.company = company;
//private member
var age = 24;
//private method
var getAge = function(){
return this.age;
};
//public method
this.displayAge = function(){
console.log(getAge());
}
}
//invoking
var t = new test(1, 'XYZ Corp');
t.displayAge(); //undefined
Почему он не получает отображаетсяИспользование частных пользователей и методы в JavaScript
'this.getAge()' –
Что вы называете «частным членом», являются простыми * локальными переменными *. Вы не сможете получить к ним доступ, используя 'this'. Читайте http://stackoverflow.com/q/13418669/1048572 – Bergi