码迷,mamicode.com
首页 > 编程语言 > 详细

判断Javascript对象是否为空

时间:2017-06-22 14:46:10      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:other   script   microsoft   ros   blog   prot   obj   pes   枚举   

判断普通javascript对象是否为空(含有可枚举的属性,自有的、继承的都可以),可使用jQuery 3.2.1版的isEmptyObject()方法:

isEmptyObject: function( obj ) {
    var name;
    for ( name in obj ) {
        return false;
    }
    return true;
}

As of jQuery 1.4 this method checks both properties on the object itself and properties inherited from prototypes (in that it doesn‘t use hasOwnProperty). The argument should always be a plain JavaScript Object as other types of object (DOM elements, primitive strings/numbers, host objects) may not give consistent results across browsers. To determine if an object is a plain JavaScript object, use $.isPlainObject()

判断Javascript对象是否为空

标签:other   script   microsoft   ros   blog   prot   obj   pes   枚举   

原文地址:http://www.cnblogs.com/sea-breeze/p/7064812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!