var arr = [1, 2, 3];
var obj = {1: 10};
var fn = () => {};
var str = new String('111');
console.log(' arr instanceof Array: ', arr instanceof Array)
console.log(' arr instanceof Object: ', arr instanceof Object)
console.log(' obj instanceof Object: ', obj instanceof Object)
console.log(' fn instanceof Function: ', fn instanceof Function)
console.log(' fn instanceof Object: ', fn instanceof Object)
console.log(' str instanceof String: ', str instanceof String)
console.log('由此证明 instanceof 只能判断数组、函数,不能够判断对象,因为函数数组皆是对象的实例')
console.log((2129-2508)*1.5)
console.log(' Object.prototype.toString.call(obj): ', Object.prototype.toString.call(str))
function fnn () {
}
console.log(fnn.prototype)
console.log(fnn.prototype.constructor === fnn)
async function myAsync (flag) {
return new Promise((resolve, reject) => {
flag ? resolve('aaaaaaaa') : reject('bbbbbbbb')
})
}
myAsync(true).then(res=> {
console.log('res: ', res) // aaaaaaaa
}).catch(err => {
console.log('err: ', err)
})
myAsync(false).then(res=> {
console.log('res: ', res)
}).catch(err => {
console.log('err: ', err) // bbbbbbbb
})
console.log(Object.prototype.toString.call(obj))
async function myAsync2(flag) {
return new Promsie((resolve, reject) => {
flag ? resolve(flag) : reject(flag)
})
}
myAsync2(true).then(res => {
console.log('res: ', res)
}).catch(err => {
console.log('err: ', err)
})
console