0

派生オブジェクトは、そのプロトタイプ オブジェクトからプロパティの値を取得できます。ただし、そのプロパティを設定すると、派生オブジェクトに新しいプロパティが追加されます。詳細は以下のコードを参照してください。

function Base(name) {this.name  = name };

function Deriver(name) {this.dname  = name };
var base = new Base('base');
Deriver.prototype = base  ;


d1 = new Deriver('d1');
console.log(d1.name);  // it will show "base". That'ok.



d1.name = "new name"; // !!! it does not update the property from its protoype object
                      // it add new property "name" in the object d1. 
console.log(d1.name); // it will show "new name" 
console.log(base.name); // it still show "base"
4

0 に答える 0