//扩展对象的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());

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-08-04
  • 2021-09-28
  • 2021-11-02
  • 2022-02-08
猜你喜欢
  • 2021-12-27
  • 2022-12-23
  • 2021-11-05
  • 2021-09-28
  • 2022-12-23
  • 2021-11-25
相关资源
相似解决方案