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
WBOYOriginal
2016-05-16 17:13:511116browse

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"));

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