读书人

判断是不是为普通的对象

发布时间: 2012-08-24 10:00:20 作者: rapoo

判断是否为普通的对象

isPlainObject:function (o) { /**   * toString.call(node) : ie678 == '[object Object]',other =='[object HTMLElement]'   * 'isPrototypeOf' in node : ie678 === false ,other === true   */     return o && toString.call(o) === '[object Object]' && 'isPrototypeOf' in o;},

?

IE浏览器采用toString()方法检验,其他浏览器查看属性中是否有isPrototypeOf来判断,o就是你要判断的“对象(目标)”。

读书人网 >Web前端

热点推荐