instanceof: examines the relationship between prototype objects and instance objects
For example: alert(cat1 instanceof Cat); //true alert(cat2 instanceof Cat); //true
Cat is the prototype object, cat1 and cat2 are instance objects.
isPrototypeOf(): Determine the relationship between an proptotype
object and an instance.
alert(Cat.prototype.isPrototypeOf(cat1)); //true
proptotype
Object: Every constructor has a prototype
property that points to another object. All properties and methods are inherited by the instance of the constructor.
hasOwnProperty(): Determine the origin of a property (it can be a local property or a property of an inherited prototype
object. )
alert(cat1.hasOwnProperty("type")); // false
in operator
1) Determine whether an instance contains an attribute
alert("name" in cat1); // true alert("type" in cat1); // true
2) Iterate over all properties of an object
for(var prop in cat1) { alert("cat1["+prop+"]="+cat1[prop]); }
Here are just some methods selected, and the specific usage needs to be used flexibly.