1
私はなぜ警告(John.hasOwnProperty( 'firstName')); firstNameはPersonプロトタイプで定義されていますが、インスタンスのJohnでは定義されていませんが、trueを返します。javascript hasOwnPropertyはfalseの代わりにtrueを返しますか?
https://jsfiddle.net/xfdnsg2w/
Person = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
var John = new Person("John");
alert(John.hasOwnProperty('toString'));
alert(John.hasOwnProperty('firstName'));
'Person.prototype'で定義している場合は、' Person.prototype.firstName'にそれを割り当てます。あなたの 'firstName'や' lastName'のようなプロパティは通常、あなたが持っている方法で定義され、インスタンス固有です(プロトタイプチェーンではなくオブジェクト自体が所有します)。 –