Sebastian Sastre
2007-Jun-08 18:44 UTC
How could "Element.extend is not a function" be happening?
Hi there, I''ve see a couple of questions about this but none with a direct answer. The thing is that today I''ve starting to see this message with Firebug. In which situation could possibly be this true? Element.extend is not a function I''m using var Prototype = { 10 Version: ''1.5.1_rc1'', ... in Firefox 2.0.0.4 Debuggin from my own code just after it calls a var candidate = $(anElementId) I followed this: function $(element) { 1227 if (arguments.length > 1) { 1228 for (var i = 0, elements = [], length = arguments.length; i < length; i++) 1229 elements.push($(arguments[i])); 1230 return elements; 1231 } 1232 if (typeof element == ''string'') 1233 element = document.getElementById(element); 1234 return Element.extend(element); 1235} and executing line by line I saw that it reaches line 1233 with the appropriate (unextended) element and when executing line 1234 it says "Element.extend is not a function" Surely something basic is going on here but I''m unable to see what. Does anybody see what is going on? thanks, Sebastian PS: all this code is being executed starting from an invocation in the onLoad() of the script of the page --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Sebastian Sastre
2007-Jun-11 17:16 UTC
Re: How could "Element.extend is not a function" be happening?
Hi there, I''m still stuck on this. I''m using last Prototype version (downloaded yesterday) There is a chance that $() could be invoked in an inappropriate time? as if something in Prototype were not yet loaded or kind of situation like that? With firebug I see the prototype.js and my own js that uses it so I guess that the two are loaded normally. Googling I saw one guy that reports same error message and solved it reinstalling the framework he was using. Here is more simple there is nothing more than prototype scriptaculous and my own script. This is intriguing cheers, Sebastian On Jun 8, 3:44 pm, Sebastian Sastre <ssas...-luH6fFXSdSWH0oMTQjrRWA@public.gmane.org> wrote:> Hi there, > > I''ve see a couple of questions about this but none with a direct > answer. > > The thing is that today I''ve starting to see this message with > Firebug. In which situation could possibly be this true? > > Element.extend is not a function > > I''m using > > var Prototype = { > 10 Version: ''1.5.1_rc1'', > ... > > in Firefox 2.0.0.4 > > Debuggin from my own code just after it calls a > > var candidate = $(anElementId) > > I followed this: > > function $(element) { > 1227 if (arguments.length > 1) { > 1228 for (var i = 0, elements = [], length = arguments.length; i < > length; i++) > 1229 elements.push($(arguments[i])); > 1230 return elements; > 1231 } > 1232 if (typeof element == ''string'') > 1233 element = document.getElementById(element); > 1234 return Element.extend(element); > 1235} > > and executing line by line I saw that it reaches line 1233 with the > appropriate (unextended) element and when executing line 1234 it says > "Element.extend is not a function" > > Surely something basic is going on here but I''m unable to see what. > Does anybody see what is going on? > > thanks, > > Sebastian > PS: all this code is being executed starting from an invocation in the > onLoad() of the script of the page--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Sebastian Sastre
2007-Jun-11 20:41 UTC
Re: How could "Element.extend is not a function" be happening?
OK, figured out now. Was happening to me some sort of loading time/ loading order problem. For the record I''ve suggested a recomendation from a seasider of ensuring order and preventing any transident time invocation. Once things are settled enough all seems to behave as expected. I hope this help on future references, cheers, Sebastian PD: the solution was based on using onLoad of the <body> (not any other) section to call a function that basically initializes everything --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
David Dashifen Kees
2007-Jun-11 21:24 UTC
Re: How could "Element.extend is not a function" be happening?
Alternately, to avoid having to add information to the <body> tag, you could use the Event.observe() function of prototype to get the same functionality: Event.observe(window, "load", function() { /* ... do onload functions here ... */ }); Or, if you have everything you need to do within a function already -- we''ll call it init() -- you could do this: Event.observe(window, "load", init); which avoids the need for the anonymous function. Really, the two methods are roughly equivalent if you only have one function to call at the start of every page. But, if you ever need to call this function and that one a page loads, the Event.observe() function can be used twice and both functions will be called, but the onload attribute of the body makes this a little more difficult. ''Course, if you''re an enthusiast for unobtrusive javascript, the Event.observe() function is probably already your best friend. - Dash - Sebastian Sastre wrote:> OK, figured out now. Was happening to me some sort of loading time/ > loading order problem. > For the record I''ve suggested a recomendation from a seasider of > ensuring order and preventing any transident time invocation. Once > things are settled enough all seems to behave as expected. > I hope this help on future references, > cheers, > > Sebastian > PD: the solution was based on using onLoad of the <body> (not any > other) section to call a function that basically initializes everything > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Gareth Evans
2007-Jun-11 21:30 UTC
Re: How could "Element.extend is not a function" be happening?
I recently found out that calling Event.Observe(window,''load'',init) from within the onload function (it was burried in a class) doesn''t work too well... But David is right. On 6/12/07, David Dashifen Kees <dashifen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Alternately, to avoid having to add information to the <body> tag, you > could use the Event.observe() function of prototype to get the same > functionality: > > Event.observe(window, "load", function() { > /* ... do onload functions here ... */ > }); > > Or, if you have everything you need to do within a function already -- > we''ll call it init() -- you could do this: > > Event.observe(window, "load", init); > > which avoids the need for the anonymous function. Really, the two > methods are roughly equivalent if you only have one function to call at > the start of every page. But, if you ever need to call this function > and that one a page loads, the Event.observe() function can be used > twice and both functions will be called, but the onload attribute of the > body makes this a little more difficult. ''Course, if you''re an > enthusiast for unobtrusive javascript, the Event.observe() function is > probably already your best friend. > > - Dash - > > Sebastian Sastre wrote: > > OK, figured out now. Was happening to me some sort of loading time/ > > loading order problem. > > For the record I''ve suggested a recomendation from a seasider of > > ensuring order and preventing any transident time invocation. Once > > things are settled enough all seems to behave as expected. > > I hope this help on future references, > > cheers, > > > > Sebastian > > PD: the solution was based on using onLoad of the <body> (not any > > other) section to call a function that basically initializes everything > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Sebastian Sastre
2007-Jun-11 22:08 UTC
Re: How could "Element.extend is not a function" be happening?
Hi David, I think I understand what you mean, but I''m not creatively adding *stuff* to the body section. The root component of the Seaside application adds for me this one call of this function that I''ve named #initializeViews. Is the only one thing that onLoad does, and it only starts this browser views framework I''m making. Everything else is a mere consequence of adequately reacting to observed events between this views instances as you properly suggested. Cheers, Sebastian On 11 jun, 18:24, David Dashifen Kees <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Alternately, to avoid having to add information to the <body> tag, you > could use the Event.observe() function of prototype to get the same > functionality: > > Event.observe(window, "load", function() { > /* ... do onload functions here ... */ > }); > > Or, if you have everything you need to do within a function already -- > we''ll call it init() -- you could do this: > > Event.observe(window, "load", init); > > which avoids the need for the anonymous function. Really, the two > methods are roughly equivalent if you only have one function to call at > the start of every page. But, if you ever need to call this function > and that one a page loads, the Event.observe() function can be used > twice and both functions will be called, but the onload attribute of the > body makes this a little more difficult. ''Course, if you''re an > enthusiast for unobtrusive javascript, the Event.observe() function is > probably already your best friend. > > - Dash - > > Sebastian Sastre wrote: > > OK, figured out now. Was happening to me some sort of loading time/ > > loading order problem. > > For the record I''ve suggested a recomendation from a seasider of > > ensuring order and preventing any transident time invocation. Once > > things are settled enough all seems to behave as expected. > > I hope this help on future references, > > cheers, > > > Sebastian > > PD: the solution was based on using onLoad of the <body> (not any > > other) section to call a function that basically initializes everything--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Gareth Evans
2007-Jun-11 22:36 UTC
Re: How could "Element.extend is not a function" be happening?
Sebastian, David is suggesting that instead of using <body onload="functionName();"> to initiate your initial call to kick everything off that you place a <script language="javascript" type="text/javascript"> Event.observe(window,"load",functionName); </script> Block at the bottom of your HTML stream being sent to the browser. This will cause prototype to register functionName against the window.onLoadevent. Event.observe(window,"load",...); can be used multiple times, *before* the stream has completed. Ie: once the browser has the complete stream, the window load event will have fired and the Event observers will not fire again for that page. Does this make things any clearer? On 6/12/07, Sebastian Sastre <ssastre-luH6fFXSdSWH0oMTQjrRWA@public.gmane.org> wrote:> > > Hi David, > > I think I understand what you mean, but I''m not creatively adding > *stuff* to the body section. The root component of the Seaside > application adds for me this one call of this function that I''ve named > #initializeViews. Is the only one thing that onLoad does, and it only > starts this browser views framework I''m making. Everything else is a > mere consequence of adequately reacting to observed events between > this views instances as you properly suggested. > > Cheers, > > Sebastian > > On 11 jun, 18:24, David Dashifen Kees <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Alternately, to avoid having to add information to the <body> tag, you > > could use the Event.observe() function of prototype to get the same > > functionality: > > > > Event.observe(window, "load", function() { > > /* ... do onload functions here ... */ > > }); > > > > Or, if you have everything you need to do within a function already -- > > we''ll call it init() -- you could do this: > > > > Event.observe(window, "load", init); > > > > which avoids the need for the anonymous function. Really, the two > > methods are roughly equivalent if you only have one function to call at > > the start of every page. But, if you ever need to call this function > > and that one a page loads, the Event.observe() function can be used > > twice and both functions will be called, but the onload attribute of the > > body makes this a little more difficult. ''Course, if you''re an > > enthusiast for unobtrusive javascript, the Event.observe() function is > > probably already your best friend. > > > > - Dash - > > > > Sebastian Sastre wrote: > > > OK, figured out now. Was happening to me some sort of loading time/ > > > loading order problem. > > > For the record I''ve suggested a recomendation from a seasider of > > > ensuring order and preventing any transident time invocation. Once > > > things are settled enough all seems to behave as expected. > > > I hope this help on future references, > > > cheers, > > > > > Sebastian > > > PD: the solution was based on using onLoad of the <body> (not any > > > other) section to call a function that basically initializes > everything > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
David Dashifen Kees
2007-Jun-12 00:48 UTC
Re: How could "Element.extend is not a function" be happening?
I agree, then, in your specific case, using the onLoad attribute of the body tag will have the same results. But, there''s a (growing) trend in client-side programming to try and separate the behavior of a page (javascript) from the display of the page (html and css). Even with respect to the display of the page, we have a separation between structure (html) and style (css). I just wanted to make sure you were aware of the Event.observe() functionality. Now that you know it''s available, you may find the need for it later on. Plus, it''s handy to use Event.observe on the window''s load event because you know that (a) all DOM elements will be available to javascript and (b) that Prototype has performed its extensions on Javascript. Thus, using it can often help to avoid some of the errors that can be caused by improperly using javascript. Sebastian Sastre wrote:> Hi David, > > I think I understand what you mean, but I''m not creatively adding > *stuff* to the body section. The root component of the Seaside > application adds for me this one call of this function that I''ve named > #initializeViews. Is the only one thing that onLoad does, and it only > starts this browser views framework I''m making. Everything else is a > mere consequence of adequately reacting to observed events between > this views instances as you properly suggested. > > Cheers, > > Sebastian > > On 11 jun, 18:24, David Dashifen Kees <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Alternately, to avoid having to add information to the <body> tag, you >> could use the Event.observe() function of prototype to get the same >> functionality: >> >> Event.observe(window, "load", function() { >> /* ... do onload functions here ... */ >> }); >> >> Or, if you have everything you need to do within a function already -- >> we''ll call it init() -- you could do this: >> >> Event.observe(window, "load", init); >> >> which avoids the need for the anonymous function. Really, the two >> methods are roughly equivalent if you only have one function to call at >> the start of every page. But, if you ever need to call this function >> and that one a page loads, the Event.observe() function can be used >> twice and both functions will be called, but the onload attribute of the >> body makes this a little more difficult. ''Course, if you''re an >> enthusiast for unobtrusive javascript, the Event.observe() function is >> probably already your best friend. >> >> - Dash - >> >> Sebastian Sastre wrote: >> >>> OK, figured out now. Was happening to me some sort of loading time/ >>> loading order problem. >>> For the record I''ve suggested a recomendation from a seasider of >>> ensuring order and preventing any transident time invocation. Once >>> things are settled enough all seems to behave as expected. >>> I hope this help on future references, >>> cheers, >>> >>> Sebastian >>> PD: the solution was based on using onLoad of the <body> (not any >>> other) section to call a function that basically initializes everything >>> > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Sebastian Sastre
2007-Jun-12 20:51 UTC
Re: How could "Element.extend is not a function" be happening?
Hi Gareth, David, firstly I want to thank you for the detailed information on the subject because this clarification demystify this apparently *transident* effect. Update: now I''m using the observe hook for the load event in the onLoad as Gareth detailed so the initialization function is guaranteed that will be called at a proper time. Believe me I love events and model/view AKA ''structure and style'' decoupling so much that I''m working on this little js framework that will allow me in ''the big picture'' to mimic a MVC - Model View Controller way but for web development. The view part of this framework *should* be in the browser that''s why I''m using js, it''s only possible if it has events implemented (which thanks the state of js now is possible) and with ajax, well, one solves in half duplex the async messages. Anecdotally, the MC part is in Seaside (but this is 99% rigorous). So the information you give me David, confirms that I''m in the right path. Thank you very much for your attention, cheers, Sebastian On Jun 11, 9:48 pm, David Dashifen Kees <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I agree, then, in your specific case, using the onLoad attribute of the > body tag will have the same results. But, there''s a (growing) trend in > client-side programming to try and separate the behavior of a page > (javascript) from the display of the page (html and css). Even with > respect to the display of the page, we have a separation between > structure (html) and style (css). I just wanted to make sure you were > aware of the Event.observe() functionality. Now that you know it''s > available, you may find the need for it later on. Plus, it''s handy to > use Event.observe on the window''s load event because you know that (a) > all DOM elements will be available to javascript and (b) that Prototype > has performed its extensions on Javascript. Thus, using it can often > help to avoid some of the errors that can be caused by improperly using > javascript. > > Sebastian Sastre wrote: > > Hi David, > > > I think I understand what you mean, but I''m not creatively adding > > *stuff* to the body section. The root component of the Seaside > > application adds for me this one call of this function that I''ve named > > #initializeViews. Is the only one thing that onLoad does, and it only > > starts this browser views framework I''m making. Everything else is a > > mere consequence of adequately reacting to observed events between > > this views instances as you properly suggested. > > > Cheers, > > > Sebastian > > > On 11 jun, 18:24, David Dashifen Kees <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> Alternately, to avoid having to add information to the <body> tag, you > >> could use the Event.observe() function of prototype to get the same > >> functionality: > > >> Event.observe(window, "load", function() { > >> /* ... do onload functions here ... */ > >> }); > > >> Or, if you have everything you need to do within a function already -- > >> we''ll call it init() -- you could do this: > > >> Event.observe(window, "load", init); > > >> which avoids the need for the anonymous function. Really, the two > >> methods are roughly equivalent if you only have one function to call at > >> the start of every page. But, if you ever need to call this function > >> and that one a page loads, the Event.observe() function can be used > >> twice and both functions will be called, but the onload attribute of the > >> body makes this a little more difficult. ''Course, if you''re an > >> enthusiast for unobtrusive javascript, the Event.observe() function is > >> probably already your best friend. > > >> - Dash - > > >> Sebastian Sastre wrote: > > >>> OK, figured out now. Was happening to me some sort of loading time/ > >>> loading order problem. > >>> For the record I''ve suggested a recomendation from a seasider of > >>> ensuring order and preventing any transident time invocation. Once > >>> things are settled enough all seems to behave as expected. > >>> I hope this help on future references, > >>> cheers, > > >>> Sebastian > >>> PD: the solution was based on using onLoad of the <body> (not any > >>> other) section to call a function that basically initializes everything--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Sebastian Sastre
2007-Jun-12 22:42 UTC
Re: How could "Element.extend is not a function" be happening?
Sorry but I have to make a correction. I''ve had to take back one version of the onLoad and call directly the function. I can''t figure out yet why if I put: Event.observe(window,"onLoad",this.initializeBrowserView) in the onLoad() of body the initializeBrowserView function is not executed when is supposed to. I''ve tried some variations onload, onLoad, load with same results cheers, Sebastian PD: first I''ve have passed in the third argument the string of the name of the function, then called the fuction like this "this.initializeBrowserView()" which gives an error about js conversion failure. Then I''ve figured out that they need the function object to be passed which has a lot more sense than strings or other ''creative'' things. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
David Dashifen Kees
2007-Jun-13 15:35 UTC
Re: How could "Element.extend is not a function" be happening?
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. 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". 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 - Sebastian Sastre wrote:> Sorry but I have to make a correction. I''ve had to take back one > version of the onLoad and call directly the function. I can''t figure > out yet why if I put: > > Event.observe(window,"onLoad",this.initializeBrowserView) > > in the onLoad() of body the initializeBrowserView function is not > executed when is supposed to. I''ve tried some variations onload, > onLoad, load with same results > > cheers, > > Sebastian > PD: first I''ve have passed in the third argument the string of the > name of the function, then called the fuction like this > "this.initializeBrowserView()" which gives an error about js > conversion failure. Then I''ve figured out that they need the function > object to be passed which has a lot more sense than strings or other > ''creative'' things. > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Sebastian Sastre
2007-Jun-14 18:17 UTC
Re: How could "Element.extend is not a function" be happening?
I''ll answer below, On 13 jun, 12:35, David Dashifen Kees <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---