检查对象类型
基本数据类型
typeof
检查对象数据类型
instanceof
对象 instanceof 数据类型
arr instanceof Array
=>true
对象分类
内置对象
Object Array Data ...
自定义对象
function Phone(color, type) {
this.color = color
this.type = type
this.call = function () {
console.log(this.type + this.color + '打电话');
}
this.sendMessage = function () {
console.log(this.type + this.color + '发短信');
}
}
function test1() {
let num = '100'
console.log(typeof num)
}
function test2() {
let arr = new Array(10, 20, 30)
let p1 = new Phone('白色', 'iphone18')
let p2 = new Phone('黑色', 'samsang8900')
if( p1 instanceof Phone ){
alert('p1是Phone手机类型')
}else{
alert('p1不是Phone手机类型')
}
}
test2()