You can define getter for appas follows:
var app = function () {
this.newvar = 'Hello world!';
};
app.prototype = {
get oldvar() {
console.log('oldvar is old!');
return this.newvar;
}
};
var myapp = new app();
alert(myapp.oldvar);
Node.js v0.10.32 JSFiddle Chrome , , . ECMA Script, . Mozilla Developer Docs .
prototype app. , , app - . , , , :
var app = function () {
this.newvar = 'Hello world!';
};
Object.defineProperty(app.prototype, 'oldvar', {
get: function () {
console.log('oldvar is old!');
return this.newvar;
}
});
var myapp = new app();
alert(myapp.oldvar);
, get ters . , delete JavaScript, .. delete app.prototype.oldvar;.