如下所示:
复制代码 代码如下:
//扩展对象的count方法
Object.prototype.count = (
Object.prototype.hasOwnProperty(‘__count__')
) ? function () {
return this.__count__;
} : function () {
var count = 0;
for (var i in this) if (this.hasOwnProperty(i)) {
count ++;
}
return count;
};
//使用
var myObj = {
name1: “value1″,
name2: “value2″
};
alert(myObj.count());
最后
以上就是懦弱大雁最近收集整理的关于获得Javascript对象属性个数的示例代码的全部内容,更多相关获得Javascript对象属性个数内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复