睦牧

博客园 首页 新随笔 联系 订阅 管理

Object.prototype.isPrototypeOf()  /  Array.prototype.isPrototypeOf()
if(typeof items === "object"&&!Array.prototype.isPrototypeOf(items)){
  items= [items];
}

constructor属性
if(typeof obj == 'object' && obj.constructor == Array){}

Instanceof

每个对象都有一个constructor属性,它引用了初始化该对象的构造函数,比如判断未知对象的类型,因此我们可以如下写一个方法,代码如下:

if([] instanceof Array){}
if({} instanceof Object){}

posted on 2019-03-21 19:20  睦牧  阅读(136)  评论(0编辑  收藏  举报