ich eine Eigenschaft auf eine Funktion geben, und diese Funktion als Konstruktor verwenden, wie folgt aus:Ist diese JavaScript-Eigenschaft eine Instanzeigenschaft oder eine Prototypeigenschaft?
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
Sehr seltsam, in meinem Test, ‚hoch‘ ist weder eine Instanz Eigenschaft
hinst.hasOwnProperty)
oder eine Eigenschaft prototype
hasPrototypeProperty(hinst,'high')
und die letzte Zeile wirft eine Ausnahme zu sagen
TypeError: Cannot read property 'constructor' of undefined
Ich nehme an, ich habe etwas Verständnis auf dem Grundstück, wie könnte 'Hinst' 'High' Eigentum besuchen?
'high' ist Eigentum des Konstruktor, so:' hinst.constructor.high' zurückkehren ' "2.0" sollte'. 'hinst.constructor.hasOwnProperty ('high')' => 'true'. – undefined