js is how to determine the properties of the object instance attribute or attributes prototype

hasOwnProperty ECMAScript5 in () method for determining the presence and only when the attribute of the object instance, returns true, the operator returns true in as long as access to property through the object.

So long as the operator returns true in hasOwnProperty () returns false, you can determine the properties of the prototype attributes.

So we have the following functions:

function hasPrototypeProperty(obj, name) {
    return !obj.hasOwnProperty(name) && (name in obj);
}

When the object instance attribute exists, the function returns false, indicating that the attribute is not present on the prototype, when the attribute is present prototype, the function returns true.

Guess you like

Origin www.cnblogs.com/jsydb/p/12240072.html
Recommended