Hi,

> Is this what bind() is for?  Can I *bind* my json object to a function
> that refers back to the original object?

FWIW, I'd say it's a clever use of bind().  The question of whether
it's what bind() is *for* is kind of moot.  (I'd say, on balance, yes
it is -- bind() is for binding functions to objects [or maybe vice-
versa].  This isn't the way you normally see it used, but that's a
different matter...)  So yeah, if you don't need the context ("this")
for some other purpose, no reason you can't do it like that.

Once you're at the point where you have your JSON data turned back
into an object (I'll call it 'json'), hooking up an event handler
would look like this:

$('someElement').observe('click', clickHandler.bind(json));

Then when someone clicks that element and your clickHandler() function
is called, you have access to 'json' within your function as "this":

function clickHandler(evt)
{
    // Get the blarg from json:
    var blarg = this.blarg;
}

I don't think I've seen anyone do quite that thing before, but it
seems like a perfectly valid use of bind().

HTH,
--
T.J. Crowder
tj / crowder software / com

On Oct 17, 7:49 pm, pancakes <[EMAIL PROTECTED]> wrote:
> I have searched around for some answer to this and I have a feeling I
> could make it work using bind(), but I'm not sure - I'm not exactly
> understanding the examples and explanations in regard to my example.
>
> I am returning a json object from the server/ajax.  I am building some
> page elements using the json object.  I'd like to allow the user to
> click on the newly updated content and have that click update a
> different part of the page.  But I'd like to reference the original
> json object, rather than pass all of the relevant information in the
> onclick.
>
> Is this what bind() is for?  Can I *bind* my json object to a function
> that refers back to the original object?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to