This is less a prototype question that a javascript question.
The syntax
function(p) {
return p;
}
creates an anonymous (unnamed) function. Thus
var obj = {
onSuccess: function(p) {
return p;
}
}
is an object whose onSuccess field which contains that function. You
can also certainly name the function in the usual way, however.
function identity(p) {
return p;
}
var obj1 = {
onSuccess: identity
}
var obj2 = {
onSuccess: identity
}
Both obj1 and obj2's onSuccess field now points to the identity function.
Another way to avoid the repetition would be to create a wrapper for
Ajax.Request which sets the onSuccess anonymously.
On 5/29/07, youngApprentice <[EMAIL PROTECTED]> wrote:
>
> Pardon this question if it's been asked many times.
>
> I'll have a couple of functions that make Ajax calls, and I need to
> know how to set things up so a single function can be run on success
> of either ajax request. Every example I see is showing onSuccess:
> function(transport) etc. and need to know how to pass the response
> text to my own function elsewhere in the JavaScript file.
>
> TIA,
>
> youngApprentice
>
>
> >
>
--
Jesse E.I. Farmer
e: [EMAIL PROTECTED]
w: http://20bits.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---