如何判断一个对象是否是Set、Map、Array、Object
参考链接:
https://blog.csdn.net/yunchong_zhao/article/details/115915624
let set = new Set()
let map = new Map()
let arr = []
let obj = {}console.log(Object.prototype.toString.call(obj)); // [object Object]
console.log(Object.prototype.toString.call(arr)); // [object Array]
console.log(Object.prototype.toString.call(set)); // [object Set]
console.log(Object.prototype.toString.call(map)); // [object Map]console.log(set.constructor == Set); // true
console.log(map.constructor == Map); // true
console.log(arr.constructor == Array); // true
console.log(obj.constructor == Object); // trueconsole.log("-------------------");console.log(Set.prototype.isPrototypeOf(set)); // true
console.log(Array.prototype.isPrototypeOf(arr)); // true
console.log(Object.prototype.isPrototypeOf(obj)); // true
console.log(Map.prototype.isPrototypeOf(map)); // trueconsole.log("-------------------");console.log(set instanceof Set); // true
console.log(arr instanceof Array); // true
console.log(map instanceof Map); // true
console.log(obj instanceof Object); // trueconsole.log("-------------------");console.log(set.__proto__ === Set.prototype); // true
console.log(map.__proto__ === Map.prototype); // true
console.log(obj.__proto__ === Object.prototype); // true
console.log(arr.__proto__ === Array.prototype); // true