获得javascript 对象的属性个数 ...
时间:2010-08-09 来源:teresa502
- //扩展对象的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());
相关阅读 更多 +
排行榜 更多 +









![《小朋友齐打交2复刻版》 v2.14d升级档+未加密补丁[TENOKE]](https://images.phpfans.net/img/f1/20251229/logo_69527f2a9daf81.jpg)
