Home > Web Front-end > JS Tutorial > A brief analysis of the application of hasOwnProperty method_javascript skills

A brief analysis of the application of hasOwnProperty method_javascript skills

WBOY
Release: 2016-05-16 17:13:51
Original
1113 people have browsed it

The hasOwnProperty function method in JavaScript returns a Boolean value indicating whether an object has a property with the specified name.

Usage:
object.hasOwnProperty(proName)

The parameter object is required. An instance of an object.
proName is required. A string value for the property name.

If the object has a property with the specified name, the hasOwnProperty function method in JavaScript returns true; otherwise, it returns false. This method cannot check whether the property is in the object's prototype chain; the property must be a member of the object itself. In the following example, all String objects share a common split method. The code below will output false and true.

var s = new String("JScript");
print(s.hasOwnProperty("split"));
print(String.prototype.hasOwnProperty("split"));

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