A more robust and generic solution for modern browsers :
!Object.implement && Object.defineProperty (Object.prototype, 'implement', {
// based on http://www.websanova.com/tutorials/javascript/extending-javascript-the-right-way
value: function (mthd, fnc, cfg) { // adds fnc to prototype under name mthd
if (typeof mthd === 'function') { // find mthd from function source
cfg = fnc, fnc = mthd;
(mthd = (fnc.toString ().match (/^function\s+([a-z$_][\w$]+)/i) || [0, ''])[1]);
}
mthd && !this.prototype[mthd] &&
Object.defineProperty (this.prototype, mthd, {configurable: !!cfg, value: fnc, enumerable: false});
}
});
// Allows you to do
String.implement (function trim () { return this.replace(/^\s+|\s+$/g, ''); });
As explained in the referenced web site, this code ensures that the method is properly hidden when iterating over the object properties. It also only adds the method if one does not already exist.
See http://jsfiddle.net/jstoolsmith/nyeeB/