1
これは私のコードです:私はこのコードを実行するとjavascriptのプロトタイプ継承はどのように機能しますか?
var Quo = function(string) { //This creates an object with a 'status' property.
this.status = string;
};
Quo.get_status = function() {
return this.status;
}
Quo.get_status = function() {
return this.status;
}
var myQuo = new Quo("confused"); //the `new` statement creates an instance of Quo().
document.write(myQuo.get_status()); //Why doesnt the get_status() method attach to the new instance of Quo?
結果は[object Object]
です。私の質問は、コンストラクタのプロパティは、インスタンスによって継承されていますか?
- どのようなプロパティがプロトタイプオブジェクトに含まれていますデフォルトでは? – dopatraman
@codeninja - チェーンです。デフォルトでは、 'Object.prototype'の全てがありますが、他のものから「拡張」することも可能です。私が – Matt
@ MattとリンクしたMDCの記事を見てください。そうすれば、Quoが作成されたとき、Quo.prototypeは空ですか?それともQuoのプロパティを含んでいますか? 注:私はまだMDNの記事を見ていません。 – dopatraman