isPrototypeOf和instanceOf
作者:
码农的世界你不懂 | 来源:发表于
2017-02-25 15:00 被阅读0次instanceOf 用于检查对象是否是某个构造函数(类型)的实例
<script>
var arr = [1,2,3];
console.log(arr instanceof Array); //true
console.log(Array instanceof Object); //true
console.log(arr instanceof Object); //true
//instanceOf在判断的时候,算上整条原型链
//arr 是Array 和Object 任何一个类的示例
</script>
isProtoTypeOf 判断是否是某个实例对象的原型对象
<script>
function Person() {
}
function Dog() {
}
Person.prototype.name = "嘿嘿";
var p1 = new Person();
console.log(Person.prototype.isPrototypeOf(p1)); //rue
console.log(Object.prototype.isPrototypeOf(p1)); //true
console.log(Dog.prototype.isPrototypeOf(p1)); //false
</script>
本文标题:isPrototypeOf和instanceOf
本文链接:https://www.haomeiwen.com/subject/tuxnwttx.html
网友评论