-
//扩展对象的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 对象的属性个数
最新推荐文章于 2023-11-14 15:27:40 发布