I got the answer from a coworker. He's not on SO so I'm posting on his behalf and will buy him a beer the next time we are in the same city:
Class.refactor doesn't work on Natives (Element, Array, String, etc.)
because they aren't Classes nor can they be overrided to be; MooTools just
adds some cool prototypes to make them more Class-like and fun and easy to
work with.
The way to extend natives is to use the implement() method; The only problem
is that this.parent() and this.previous() don't exist, so you have to get a
bit trickier to extend existing methods without rewriting them:
(function(){ // Keeps the window namespace clean
var old_hide = Element.prototype.hide;
var old_show = Element.prototype.show;
Element.implement({
hide: function() {
result = old_hide.run(arguments, this); // Calls old method
alert("Hiding " + this.get('tag') );
return result;
},
show: function(display) {
result = old_show.run(arguments, this); // Calls old method
alert("Showing " + this.get('tag') );
return result;
}
});
})(); // Closes the private function and executes it immediately
The key concepts here are:
1 - Encapsulate the whole shebang in a private, self-executing function so
the global namespace isn't polluted by our variable assignments for the
original methods (e.g. old_hide and old_show);
2 - Use the Native object's implement() method to override each function,
much like you had done as the second argument to Class.refactor;
3 - Instead of calling this.parent() or this.previous() in each method, you
call the old prototypes using MooTools' run() method, which passes the
arguments with a binding to the function and executes it.
As before, make sure to gather the result of the function.run() call and
return it to maintain API consistency.