1 for In loop: When using it, the main traversal is all enumerable properties (instances and properties in the prototype)
function Person (name) { this. Name= name;} Person.prototype.getName=function() { returnthis. Name;} var New Person (' MENGXB '); for inch p) {// This will traverse the GetName on the prototype, and if you do not want to traverse the properties and methods on the prototype, you can use hasOwnProperty ()
if (P.hasownproperty (prop)) {
Some opertion here
}}
There is also an in operator that can be used to determine whether a property can be accessed by an instance
// using the code above in P); // true in P); // true
Tip: You can use the in operator and the hasOwnProperty method to write a new method Hasprototypeproperty ()
function Hasprototypeproperty (object, prop) { returnin object) &&! Object.hastownproperty (prop);}
The hole in JavaScript