A brief analysis on the application of hasOwnProperty method

  • 2020-03-29 23:54:06
  • OfStack

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

Usage:
Object. The hasOwnProperty (proName)

Where the parameter object is a required option. An instance of an object.
ProName is a required option. The string value of a property name.

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

Var s = new String("JScript");
Print (Sheldon horowitz asOwnProperty (" split "));
Print (String) prototype) hasOwnProperty (" split "));


Related articles: