I'll answer below,
On 13 jun, 12:35, David Dashifen Kees <[EMAIL PROTECTED]> wrote:
> Well there's three things that I see:
>
> 1. You don't have to put the Event.observe() function call in the
> onLoad attribute of the <body> tag. You can put it within a script tag
> anywhere in your document, though usually between the <head> tags, as
> long as it appears within <script> tags.
>
Yes, that was a mistake. It really has no sense to put a hook of an
event inside the action to take given that event. What do has sense is
to put it anywhere else but there :) ... so yes you're right about
that. In this case *anywhere* has not much sense outside the own
instance of the page (that was the intention in using
this.initialize..) so a direct request of initialization given the
event of load completion in the page should be well enough.
> 2. The second parameter is "load" not "onLoad" as you've done it
> below. Usually, the parameters for this function conform to the same
> names as the attribute without the "on" in front of them. Thus,
> "onClick" becomes simply "click" and "onKeyUp" would be simply "keyup".
>
I see, thank you for your clarification.
> 3. You shouldn't need the "this" keyword when calling your function as
> you're not calling an object's method, just a function you've added to
> the page. Unless I'm mistaken about your page structure, I suppose, but
> in that case, I'm not sure that "this" will refer to the object you want
> it to without using the prototype bind() function, for which you can
> find more information online.
>
> To be honest, though, I tend to use an anonymous function with my window
> loading observations. In that case, you can do something like this:
>
> Event.observe(window, "load", function() {
> /* ... put statements here ... */
>
> });
>
> Instead of defining a function and then using observe() to call it.
> That's only my style, though, and doesn't have to be yours. Just wanted
> you to know about the option.
>
> - Dash -
>
Well I used *this.initialize...* there just to remenber me to think
about *who* is the code "talking" to. There, the "this" instance is
the windows object I think. Anyway I'm not looking Firebug now but it
*should* be the whatever instance that the browser's DOM creates and
gives you as the default contextualized instance of the page. I tend
to see anonymous functions (or methods) as hacks and I really want to
make software in a non hakish style so I can allways count with the
trak of the interaction between the participant instances envolved and
in that way I don't loose the big picture of the framework. In the
other hand, when decoupling between an action and it's creation and
execution time is valuable, I love to have the posibility of having
any code in a decoupled context.
Thank you for your help David,
Cheers,
Sebastian
PD: by the way I found the #bind() function you've mentioned pretty
interesting when contextualization is needed. That will be handy for
sure. I'm glad to know Prototype is providing JS with this kind of
features.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---