欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

獲得Javascript對象屬性個數(shù)的示例代碼

 更新時間:2013年11月21日 09:13:17   作者:  
這篇文章主要是對獲得Javascript對象屬性個數(shù)的示例代碼進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助
如下所示:
復(fù)制代碼 代碼如下:

//擴展對象的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());

相關(guān)文章

最新評論