参考答案:
能。比如下面这种方式:
1class PrimitiveNumber { 2 static [Symbol.hasInstance](x) { 3 return typeof x === 'number' 4 } 5} 6console.log(111 instanceof PrimitiveNumber) // true 7
其实就是自定义instanceof行为的一种方式,这里将原有的instanceof方法重定义,换成了typeof,因此能够判断基本数据类型。
最近更新时间:2021-07-07
题库维护不易,您的支持就是我们最大的动力!