Created
May 15, 2014 19:44
-
-
Save formariz/57d43b81299a71d1d596 to your computer and use it in GitHub Desktop.
Object length
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.prototype.length = function() { | |
var count = 0, key; | |
for (key in this) { | |
if (this.hasOwnProperty(key)) count++; | |
} | |
return count; | |
} | |
/** | |
* Example of use | |
**/ | |
// Create the object | |
var myObject = new Object({ 100: "a", 28: "b", 71: "c"}); | |
// Alert length of Object | |
alert(myObject.length()); // return 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment