I love the idea of extending scope manipulation to any function,
rather than only event handlers.  Callbacks to ajax requests often
need a better scope than the XHR, and while I look forward to 1.4's
functionality for event handlers, it would really be a shame to
continue to force people to use non-jQuery solutions for full scope
manipulation.

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

On Dec 29, 3:45 pm, Peter Higgins <phigg...@gmail.com> wrote:
> It is a short-port of Dojo's dojo.hitch(). The only thing it doesn't do
> that Dojo's does is currying the arguments in the original hitched
> function, eg:
>
> // a bad example off the top of my head
> var x = $(".nodes");
> var clicker = $.hitch(x, "bind", "click");
>
> clicker(function(e){
>     // this just called $(.nodes").bind("click", arguments[0])
>
> });
>
> It would be another few bytes to support that. dojo.partial is equally
> as neat.
>
> Regards,
> Peter
>
>
>
> Rick Waldron wrote:
> > $.hitch() is a great "fn.bind()" solution, I still want to try a
> > variety of scope related tests, but so far its really solid. I love
> > the fact that you included the exception for a non existent  method, I
> > referred to Prototype's latest and there is no such check.
>
> > Hats off.
>
> > Rick
>
> > On Tue, Dec 29, 2009 at 12:40 PM, Rick Waldron <waldron.r...@gmail.com
> > <mailto:waldron.r...@gmail.com>> wrote:
>
> >     Agreed, that is slick. As soon as I get back to the office I'm
> >     going to test it, I look forward to this.
>
> >     -- Sent from my Palm Prē
>
> >     ------------------------------------------------------------------------
> >     aHeckman wrote:
>
> >     Yeah this looks good Peter. This should be in core IMHO.
>
> >     BTW, you're running for president? LOL
>
> >     On Dec 29, 9:24 am, Peter Higgins <phigg...@gmail.com
> >     <mailto:phigg...@gmail.com>> wrote:
> >     > ... this is why I keep suggesting making the bind functionality as
> >     > explicit function call, rather than hidden away in one or two api's:
>
> >     >http://higginsforpresident.net/js/static/jq.hitch.js
>
> >     > It does not extend any native prototypes, is useful and a bit magic
> >     > (with the string->method resolution).
>
> >     > Regards,
> >     > Peter
>
> >     > aHeckman wrote:
> >     > > I too feel relying on a function.prototype.bind implementation
> >     would
> >     > > be the most forward looking but I'm not sure that jives with the
> >     > > general approach of jQuery:
>
> >     > > jQuery doesn't extend Native.prototype.anything.
>
> >     > > On Dec 29, 1:12 am, Daniel Friesen <nadir.seen.f...@gmail.com
> >     <mailto:nadir.seen.f...@gmail.com>> wrote:
>
> >     > >> Rick Waldron wrote:
>
> >     > >>> Available, as in the "scope" argument is being retrofitted to an
> >     > >>> existing function, and ONLY to that function.
>
> >     > >>>     I don't get what you are talking about a fn.bind()
> >     implementation in
> >     > >>>     jQuery, or what you mean by available in just one
> >     function though.
>
> >     > >>> Read ES5.
>
> >     > >>> function.prototype.bind()
>
> >     > >> I already read ES5, I use portions of ES5 in a number of js
> >     server-based
> >     > >> projects already.
>
> >     > >> However I don't get "ONLY" one function, since the whole point of
> >     > >> .bind() is to bind a `this` onto ONE function with one call.
> >     It's not
> >     > >> bind otherwise.
>
> >     > >> So I don't see any limitation. Unless you are under the
> >     > >> misinterpretation that after you have called .bind() on one
> >     function you
> >     > >> have modified that function and bound it's `this`. .bind()
> >     doesn't
> >     > >> modify the function, it returns a new one.
> >     > >>  From ES5 15.3.4.5 Function.prototype.bind> The bind method
> >     takes one or more arguments, thisArg and (optionally)
>
> >     > >>> arg1, arg2, etc, and returns a *new*
> >     > >>> function object by performing the following steps:
>
> >     > >> So this is valid ES5 code.
>
> >     > >> "use strict";
> >     > >> var a = function() { alert(this); };
> >     > >> var a1 = a.bind("a");
> >     > >> var a2 = a.bind("b");
>
> >     > >> a(); // Alerts undefined
> >     > >> a1(); // Alerts "a"
> >     > >> a2(); // Alerts "b"
>
> >     > >>> On Mon, Dec 28, 2009 at 7:43 PM, Daniel Friesen
> >     > >>> <nadir.seen.f...@gmail.com <mailto:nadir.seen.f...@gmail.com>
> >     <mailto:nadir.seen.f...@gmail.com
> >     <mailto:nadir.seen.f...@gmail.com>>> wrote:
>
> >     > >>>     I made a post about how confusing people may find the
> >     name bind some
> >     > >>>     time ago. Suggested renaming bind to something like
> >     event, and keeping
> >     > >>>     bind as an alias of course. That was rejected.
>
> >     > >>>     I don't get what you are talking about a fn.bind()
> >     implementation in
> >     > >>>     jQuery, or what you mean by available in just one
> >     function though.
>
> >     > >>>     ~Daniel Friesen (Dantman, Nadir-Seen-Fire)
> >     > >>>     [http://daniel.friesen.name]
>
> >     > >>>     Rick Waldron wrote:
> >     > >>>     > John,
>
> >     > >>>     > While I'm glad to see a scope arg available, i still
> >     think this is
> >     > >>>     > negligent to the future of jQuery and ES standards. I
> >     really think a
> >     > >>>     > fn.bind() implementation would ideal (since it would be
> >     jQuery-wide
> >     > >>>     > and not just available in one function), but as I've
> >     noted in
> >     > >>>     the past
> >     > >>>     > and is exampled here, beginners may find this syntax a
> >     bit boggling:
>
> >     > >>>     > $(foo).bind('event', fn.bind(bar) );
>
> >     > >>>     > Rick
>
> >     > >> ~Daniel Friesen (Dantman, Nadir-Seen-Fire)
> >     [http://daniel.friesen.name]
>
> >     > > --
>
> >     > > You received this message because you are subscribed to the
> >     Google Groups "jQuery Development" group.
> >     > > To post to this group, send email to
> >     jquery-dev@googlegroups.com <mailto:jquery-dev@googlegroups.com>.
> >     > > To unsubscribe from this group, send email to
> >     jquery-dev+unsubscr...@googlegroups.com
> >     <mailto:jquery-dev%2bunsubscr...@googlegroups.com>.
> >     > > For more options, visit this group
> >     athttp://groups.google.com/group/jquery-dev?hl=en
> >     <http://groups.google.com/group/jquery-dev?hl=en>.
>
> >     --
>
> >     You received this message because you are subscribed to the Google
> >     Groups "jQuery Development" group.
> >     To post to this group, send email to jquery-dev@googlegroups.com
> >     <mailto:jquery-dev@googlegroups.com>.
> >     To unsubscribe from this group, send email to
> >     jquery-dev+unsubscr...@googlegroups.com
> >     <mailto:jquery-dev%2bunsubscr...@googlegroups.com>.
> >     For more options, visit this group at
> >    http://groups.google.com/group/jquery-dev?hl=en.
>
> > --
>
> > 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.

--

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