After looking at jQuery recently, I became interested in the idea of adding core object prototype functions. Imagine if, instead of the normal MochiKit syntax, you could do:
var a = someObject.clone(); // var a = clone(someObject); var b = [].isArrayLike(); // var b = isArrayLike([]); var c = someFunction.partial("arg1"); // var c = partial(someFunction, "arg1"); Basically, all you need to do is add every MochiKit.Base function as a method of object.prototype, while at the same time pre-pending "this" as the first argument. Here's some (relatively untested) code I wrote to do just that: var objectMethodExportList = clone(MochiKit.Base.EXPORT); // Exclude concat to avoid conflict with Array.concat objectMethodExportList.splice(findIdentical(MochiKit.Base.EXPORT, "concat"),1); forEach(objectMethodExportList, function(x) { Object.prototype[x] = function() { return MochiKit.Base[x].apply(this, extend([this], arguments)); }; }); You could do the same thing with the DOM library and Element.prototype, and various other Mochikit functions as well (eg. "var a =A(); a.connect("onclick", someFunction);"). However, even just my initial tests showed some obvious problems. For instance, consider the keys function: it will return a ton of new properties (because methods are properties in JavaScript) on any object you pass to it. So before I waste a bunch of time trying to fix such issues, I thought it might help to ask if anyone else had played around with this sort of thing before. Or for that matter, is anyone actually using anything like this? If so, I'd love to hear about your experience. Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "MochiKit" group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~----------~----~----~----~------~----~------~--~---