私は関数の性質を与え、このように、コンストラクタとしてこの機能を使用するには:非常に奇妙な、私のテストでは、「高」は、インスタンスのプロパティでもない このjavascriptプロパティはインスタンスプロパティか、プロトタイププロパティですか?
function h(){this.a='abc';}
h.high='2.0';
var hinst=new h();
function hasPrototypeProperty(object, name){
return !object.hasOwnProperty(name) && (name in object);
}
console.log(h.hasOwnProperty('high')); //true
console.log(hinst.hasOwnProperty('high'));//false
console.log(hasPrototypeProperty(hinst, 'high'));//false
console.log('a' in hinst); //true
console.log('high' in hinst);//false
console.log(hinst.prototype.constructor.high); //exception
ある
hinst.hasOwnProperty)
またはprototypeプロパティ
hasPrototypeProperty(hinst,'high')
そして、最後の行は
を言って例外をスローします210TypeError: Cannot read property 'constructor' of undefined
私は不動産に関する理解が不足していると思われますが、どのように 'hinst'が 'high'プロパティを訪問することができますか?
'high'コンストラクタの特性であるので、' hinst.constructor.high'は '' "2.0" を返すべきです。 'hinst.constructor.hasOwnProperty( 'high')' => 'true'です。 – undefined