如下圖所示:
/擴充物件的count方法
Object.prototype.count = (
Object.prototype.hasOwnProperty('__count__')
) ? function () {
return this.__count__; var count = 0;
for (var i in this) if (this.hasOwnProperty(i)) {
count ;
🎜>//使用
var myObj = {
name1: “value1″,
name2: “value2″
}j
alert(myOb); 🎜>