Home  >  Article  >  Web Front-end  >  Javascript hasOwnProperty method & in keyword_javascript tips

Javascript hasOwnProperty method & in keyword_javascript tips

WBOY
WBOYOriginal
2016-05-16 18:58:12963browse

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.

Copy code The code is as follows:

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