Home > Web Front-end > JS Tutorial > body text

Javascript hasOwnProperty method & in keyword_javascript tips

WBOY
Release: 2016-05-16 18:58:12
Original
961 people have browsed it

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!