François Beausoleil
2005-Sep-25 21:16 UTC
[Rails-spinoffs] Preventing/allowing exceptions to occur in Element.add/remove ClassName
Hello everyone ! Thomas asked me to discuss here the behavior of Element.addClassName, as relating to ticker #2232 [1]. In HEAD, if the element passed-in to Element.addClassName does not exist, an exception is thrown, and script execution stops there. I believe this is inconsistent with other functions: Object.extend(Element, { hasClassName: function(element, className) { element = $(element); if (!element) return; //... }, removeClassName: function(element, className) { element = $(element); if (!element) return; //... }, addClassName: function(element, className) { element = $(element); Element.removeClassName(element, className); //... }, } As you can see, both hasClassName and removeClassName prevent an exception from occuring if the element does not exist. Either make all three functions throw an exception, or make all three more resilient in the face of possible errors (2/3 of the way there !). In my mind, addClassName is an omission... It should be standardized. Bye ! Fran?ois [1] http://dev.rubyonrails.org/ticket/2232
Michael Schuerig
2005-Sep-25 21:42 UTC
[Rails-spinoffs] Re: Preventing/allowing exceptions to occur in Element.add/remove ClassName
On Monday 26 September 2005 02:52, Fran?ois Beausoleil wrote:> Thomas asked me to discuss here the behavior of Element.addClassName, > as relating to ticker #2232 [1]. In HEAD, if the element passed-in > to Element.addClassName does not exist, an exception is thrown, and > script execution stops there. > > I believe this is inconsistent with other functions:> hasClassName: function(element, className) { > removeClassName: function(element, className) { > addClassName: function(element, className) {Will these zombies ever die? I wrote and send them to Sam months ago when I didn''t know about the much better Element.Class. I''ve even supplied a patch that replaces the former with the latter. Until now to no effect, alas.> As you can see, both hasClassName and removeClassName prevent an > exception from occuring if the element does not exist. Either make > all three functions throw an exception, or make all three more > resilient in the face of possible errors (2/3 of the way there !). > In my mind, addClassName is an omission... It should be > standardized.Let them all throw exceptions. These are low level functions. You really want to be notified when something goes wrong. If missing elements should be ignored, that''s fine, but a job for a higher level where this policy is set. Michael -- Michael Schuerig Life is what happens mailto:michael@schuerig.de While you''re making plans http://www.schuerig.de/michael/ --Kevin Gilbert, A Long Day''s Life
Thomas Fuchs
2005-Sep-26 04:53 UTC
[Rails-spinoffs] Re: Preventing/allowing exceptions to occur in Element.add/remove ClassName
+1 Also, i''m using the mentioned Element.Class.XXX functions that currently reside in util.js. Thomas Am 26.09.2005 um 03:18 schrieb Michael Schuerig:> On Monday 26 September 2005 02:52, Fran?ois Beausoleil wrote: >> As you can see, both hasClassName and removeClassName prevent an >> exception from occuring if the element does not exist. Either make >> all three functions throw an exception, or make all three more >> resilient in the face of possible errors (2/3 of the way there !). >> In my mind, addClassName is an omission... It should be >> standardized. >> > > Let them all throw exceptions. These are low level functions. You > really > want to be notified when something goes wrong. If missing elements > should be ignored, that''s fine, but a job for a higher level where > this > policy is set.