在JS/TS上如何判断对象类型呢
- 通过instanceof
instanceof xx type
需要知道object类型,做类型判断用func instanceof{this.__left=this.__right}
-
通过typeof
只能识别string object number null这些 -
通过Object.prototype
因为几乎所有的对象类型都是object,所以可以打印他的类型的string
Object.prototype.toString.call(this.obj)