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

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

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

//擴(kuò)展對(duì)象的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)文章

最新評(píng)論