1. isPortotypeOf() 检测当前对象是否是基于对应构造函数创建出来得
function Student(name){
this.name = name
}
Student.prototype.show = function(){
console.log(this.name)
}
var s1 = new Student("王一")
var t = Student.prototype.isPrototypeOf(s1)
console.log(t) // true
2. instanceof 用于判断变量的类型是否为当前构造函数的实例对象
function Student(name){
this.name = name
}
Student.prototype.show = function(){
console.log(this.name)
}
var s1 = new Student("王一")
var t = s1 instanceof Student
console.log(t) // true
3. hasOwnProperty() 判断当前的属性和方法是否源于对象的构造函数内部,仅限在构造函数中
function Student(name){
this.name = name
}
Student.prototype.show = function(){
console.log(this.name)
}
var s1 = new Student("王一")
var r = s1.hasOwnProperty("show")
console.log(r) // false
4. in 判断当前对象是否具有对应属性和方法
function Student(name){
this.name = name
}
Student.prototype.show = function(){
console.log(this.name)
}
var s1 = new Student("王一")
var r = "show" in s1
console.log(r) // true