The following doesn't work, from my getter, I can't see _nickname
defined in the 'class' Person.
var Person = function (args) {
var _nickname = '';
if (args === undefined || args === null) {
return;
}
if (args.nickname !== undefined && args.nickname !== null) {
_nickname = args.nickname;
}
}
Object.defineProperty(Person.prototype, "nickname", {
get : function () {
return _nickname;
}
});
var x = new Person({
nickname : 'bob'
});
console.log(x.nickname);
How should one go about accomplishing this? Is there a way of adding _nickname to the prototype of Person from within its function?