EcmaScript 5 Inheritance
by Wentz Wu
JavaScript
function Test() {
this.prop1 = 1;
this.prop2 = 2;
}
Object.defineProperty(Test.prototype, "prop3", {
get: function() {
return this.prop1 + this.prop2;
}
});
var t = new Test();
t.prop1 = 99;
console.log(t.prop3); // 3
t.prop1 = 2;
console.log(t.prop3); // 4