常用 对象检测 api

isPrototypeOf()    判断某个 proptotype 对象和某个实例之间的关系

alert(Cat.prototype.isPrototypeOf(cat1)); //true

alert(Cat.prototype.isPrototypeOf(cat2)); //true

 

hasOwnProperty()   判断某一个属性到底是本地属性,还是继承自prototype对象的属性

alert(cat1.hasOwnProperty("name")); // true

alert(cat1.hasOwnProperty("type")); // false

 

in 运算符    可以用来判断,某个实例是否含有某个属性,不管是不是本地属性

alert("name" in cat1); // true
alert("type" in cat1); // true

 

参考链接

posted @ 2018-11-09 19:59  justSmile2  阅读(179)  评论(0编辑  收藏  举报