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 Why is it not getting displayed
this. Read stackoverflow.com/q/13418669/1048572