So I wrote a function to extend Objects to count how many entries are within them, so it may be used as such:
test = {"foo": "bar", "baz": 7, "darth": "maul"}
test.count()
=> 3
I wrote the code as such:
Object.prototype.count = function() {
var count = 0, key;
for (key in this) {
if (this.hasOwnProperty(key)) {
count++;
}
}
return count;
}
This is my first attempt at extending with prototype, and I'm getting this error from within jQuery.js:
Uncaught TypeError: Object function () {
var count = 0, key;
for (key in this) {
if (this.hasOwnProperty(key)) {
count++;
}
}
return count;
} has no method 'replace'
The stacktrace points back to where I call css on a jQuery object onLoad:
$img.css({left: 20, top: 50});
Not that I think there's anything specific about that line, but I thought it may be good to provide.
Is there something I'm doing wrong here?