I found this question while searching for a general solution to making methods chainable, after they are defined. Here's what I came up with. I am a JavaScript neophyte; buyer beware.
makeChainable = function() {
var receiver = arguments[0]
for (var i = 1; i < arguments.length; i++) {
functionName = arguments[i];
(function() {
wrapped = receiver[functionName];
receiver[functionName] = function() {
wrapped.apply(receiver, arguments);
return receiver;
}
})();
}
}
daisy = {
name: 'Daisy',
moo: function() { console.log(this.name + " moos!") }
}
makeChainable(daisy, 'moo');
daisy.moo().moo().moo();