Hi,
> My understanding is that without the brackets javascript returns the
> function object rather than executing it, is this just how it has to
> be?
Yes, that's just how it is. This code:
$('element').previous.hide()
...tries to call a function called `hide` on the function object
`previous` (rather than on the result of *calling* the function). In
some situations that may be a perfectly valid thing to do, and so the
syntax can't be used to do something else. The only ways to *call* a
function in JavaScript are the usual way (by putting parens after it
[optionally including arguments to pass in]) or via the Function#call
or Function#apply functions, which wouldn't help you here if your goal
is to make things even more brief.
There's no way around it, really, not least because you may wish to
pass arguments into some of the intermediate functions.
HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com
On Mar 17, 1:25 pm, Rob Aldred <[email protected]> wrote:
> to chain methods you have to do something like the following:
> $('element').previous().hide()
>
> this is different to:
> $('element').previous.hide()
>
> the second example doesn't work I wondered if there was a way to write
> it this way rather than the first...
> My understanding is that without the brackets javascript returns the
> function object rather than executing it, is this just how it has to
> be?
--
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 [email protected].
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.