
35
2.4 実際の相違点
Winner.setWinner = function(name, country, category, year){
this.setCitizen(name, country);
this.category = category;
this.year = year;
return this;
};
Winner.printDetails = function(){
console.log('Nobel winner ' + this.name + ' from ' +
this.country + ', category ' + this.category + ', year ' +
this.year);
};
var albert = Object.create(Winner)
.setWinner('Albert Einstein', 'Switzerland', 'Physics', 1921);
albert.printDetails();
Out:
Nobel winner Albert Einstein from Switzerland, category
Physics, year 1921
❶
Citizen
は、コンストラクタ関数というよりオブジェクト。これを
Winner
などの新しい建造物の土台と
考える。
繰り返しになりますが、プロトタイプ継承は
JavaScript
のデータ可視化(特に、宣言型と関数
型のパターンに重点を置き、生のカプセル化されていないデータを使って ...