1. isPrototypeOf
IsPrototypeOf is used to determine whether the specified object object1 exists in the prototype chain of another object object2. If yes, true is returned; otherwise, false is returned.
The format is as follows:
Object1.isPrototypeOf (object2 );
Object1 is an object instance;
Object2 is another object that will check its prototype chain.
The prototype chain can be used to share functions between different instances of the same object type.
If the prototype chain of object2 contains object1, The isPrototypeOf method returns true.
If object2 is not an object or object1 does not appear in the prototype chain of object2, The isPrototypeOf method returns false.
Example:
Var re =/^ \ s */; // a regular expression object is defined here // check whether RegExp is the original chain object of re and return truevar bIsptt = RegExp. prototype. isPrototypeOf (re );
2. hasOwnProperty
HasOwnProperty determines whether an object has a named property or object. This method cannot check whether the object has this property in the prototype chain. This property must be a member of the object.
If this attribute or method is defined by the object rather than defined in the prototype chain, true is returned; otherwise, false is returned;
The format is as follows:
Object. hasOwnProperty (proName );
Determine whether the name of proName is an attribute or object of the object. Example:
// Get false because the property var bStr = "Test String" in the prototype chain cannot be detected ". hasOwnProperty ("split"); // This property is already available on the prototype of the String object, and truevar bStr1 = String is naturally returned. prototype. hasOwnProperty ("split"); // return true because the property var bObj = ({fnTest: function () {}}) is not detected in the prototype (){}}). hasOwnProperty ("fnTest ");