I am just curious as to the motivation for this; other than an extra dot, I
don't see much of a difference between:
var a = someObject.clone();
and
var a = clone(someObject);
Is it merely because you think it makes more semantic sense or . . . ? I
don't know why we would want to add more complexity to the code base for
something that isn't really giving us anything more. Please tell me what I
am missing, because I am sure there is something (it's late and my brain
doesn't function that well at this time of the morning).
Jason Bunting
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of machineghost
> Sent: Monday, June 16, 2008 10:23 PM
> To: MochiKit
> Subject: [mochikit] MochiQuery
>
>
> 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
> >
>
> No virus found in this incoming message.
> Checked by AVG.
> Version: 8.0.100 / Virus Database: 270.3.0/1505 - Release Date: 6/16/2008
> 7:20 AM
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---