Tips for using criptisprototypeof and hasOwnProperty. If you need a friend, refer.
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:
The Code is as follows:
Var re =/^ \ s */;
// Define a regular expression object
// Check whether RegExp is the original link object of re. true is returned.
Var 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:
The Code is as follows:
// Get false because the attributes in the prototype chain cannot be detected.
Var bStr = "Test String". hasOwnProperty ("split ");
// This attribute is already available on the prototype of the String object. true is returned naturally.
Var bStr1 = String. prototype. hasOwnProperty ("split ");
// Returns true because it is not an attribute in the detection prototype.
Var bObj = ({fnTest: function () {}}). hasOwnProperty ("fnTest ");