After looking through some of the other threads inheritance looks a bit complicated. the why does the getAge() function not return the this._age value in Option 1? and what is best practice between Option 1 and Option 2?
Option 1
function Person(){
this._age = 21;
}
Person.prototype.getAge(){
return this._age;//undefined
}
var person = new Person();
person.getAge();
Option 2
function Person(){
var _age = 21,
getAge:function(){
return _age;
}
}
Finally what would be the different be between the above two and the following?
var person = new Person();
person.age = 21;
I just might be confusing myself.