+1

On Dec 29, 4:39 pm, Peter Higgins <phigg...@gmail.com> wrote:
> ajpiano wrote:
> > That said, and while I do love (and frequently recommend) $.hitch, I
> > prefer an approach more like Prototype or Underscore's that doesn't
> > involve passing so many strings.
>
> > --adam
>
> You don't have to pass any strings?
>
> $(".foo").bind("click", $.hitch(this, function(e){
>     // we've preserved the parent context
>
> });
>
> var o = { b:1, j: function(t){ this.b += t } };
> var fn = $.hitch(o, o.j);
> fn(10); // bad example, but calls o.j(10) in context
>
> UnderscoreJS's bind() is very similar, though is more like dojo.partial
> (the cousin of hitch):
>
>  bind_.bind(function, object, [*arguments])
> Bind a function to an object, meaning that whenever the function is
> called, the value of this will be the object. Optionally, bind arguments
> to the function to pre-fill them, also known as currying.
>
> var func = function(greeting){ return greeting + ': ' + this.name };
> func = _.bind(func, {name : 'moe'}, 'hi');
> func();
> => 'hi: moe'
>
> The API is just "backwards". (the above example would be var fn =
> _.bind(o.j, o); )
>
> Whichever way, they are essentially the same thing.  The string stuff is
> just an extra piece of shorthand. Some like it, some don't.  My point is
> that hiding this usefulness in $.fn.bind only would only complicate
> things, but adding some 150 bytes to core to support this function
> (whichever direction the api sig goes) gives everyone the ability to use
> it and keeps the other stuff simple and backwards compatible.
>
> Regards,
> Peter

--

You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en.


Reply via email to