私は継承を使用していましたが、同じ結果を得るには 3 つの方法があることに気付きました。違いは何ですか?
function Animal(){
}
Animal.prototype.doThat = function() {
document.write("Doing that");
}
function Bird(){
}
// This makes doThat() visible
Bird.prototype = Object.create(Animal.prototype); // Solution 1
// You can also do:
// Bird.prototype = new Animal(); // Solution 2
// Or:
// Bird.prototype = Animal.prototype; // Solution 3
var myVar = new Bird();
myVar.doThat();
ご覧のとおり、私は 3 つの解決策を提案しました。それぞれがメソッド doThat() を可視化します。
それらすべてにコメントすると、実際にはエラーがあります。
それらの1つだけをコメント解除すると、プログラムは機能します。
では... 3 つのソリューションの実際の違いは何ですか?