巧记tostring、valueof、typeof、instanceof

286 阅读1分钟

1.typeof他不能检测出null,object,array。之间的区别。如果想区分数组的话,可以用Array.isArray,或者用Object.prototype.toString.call(arr)=='[object Array]'

2.instanceof用来判断构造函数的prototype是否在要被检测的对象的原型链上