Wednesday, February 21, 2007

Prototype Array fun

I must say, I love prototype and I love cliches. Prototype is the best thing since sliced bread. Okay, maybe not the absolute best thing, but it's close. For example, I was pretty mad that javascript doesn't have a function to check if an array key exists like PHP's array_key_exists function, but with prototype, I can come pretty close.

Array.prototype.keyExists = function(key) {
for (var i in this) {
if (i==key) return true;
}
return false;
};

Hopefully this is self explanatory as I'm being lazy and I'm not in the mood to write out detailed examples of how to use it.

No comments: