This method cannot check whether the property is in the object's prototype chain; the property must be a member of the object itself. The
in operation checks whether there is a property named property in the object. You can also check the object's prototype to determine whether the property is part of the prototype chain.
function Test(){
this. a= 'abc';
}
Test.prototype.b='efg';
var test=new Test;
alert(test.hasOwnProperty('a'));// Output true
alert(test.hasOwnProperty('b'));//Output false
alert('a' in test);//Output true
alert('b' in test );//Output true
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn