As shown below:
//Extend the count method of the object
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;
};
//Use
var myObj = {
name1: “value1″,
name2: “value2″
};
alert(myObj.count());
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn