luisabreu (2) [Avatar] Offline
#1
Hello.

I've started reading JQuery in Action and I've seen that the authors say this in chapter 4: "Supplying the function as an anonymous inline reference
would make it impossible to later reference the function in a call to unbind()."

This should be possible with the arguments.callee property since this should return a reference to the current execution function.

Thanks.

Luis
bear.bibeault (675) [Avatar] Offline
#2
Re: Need to use named function for using unbind method in chapter 4
The callee property of the arguments list is only available within the execution body of the function itself. So it would be possible to unbind the function in the handler itself, but that'd be a very odd use case.

The book was, of course , talking about the general case, where not having a reference to an anonymous inline function is the norm.
luisabreu (2) [Avatar] Offline
#3
Re: Need to use named function for using unbind method in chapter 4
I guess that it's just another way to implement one time event handlers. Anyway, since I'm not a native speaker, I might have misinterpreted the text...
bear.bibeault (675) [Avatar] Offline
#4
Re: Need to use named function for using unbind method in chapter 4
I'd imagine that's pretty much the way that the one() method could be implemented.

And no, I don't think that you misread anything. And pointing out the callee property might be useful to some readers that didn't previously know of it. Well done.

We didn't mention the callee property at that point in the book because it's such a niche use case, and one that's already covered by one().