[dojo-contributors] dojo.attr() does not return a number

Adam L. Peller adam at peller.org
Sun Oct 19 22:46:19 EDT 2008

The simple thing to do, and the behavior most consistent with the DOM APIs,
is to just return string.  The alternative seems a bit magical and may need
to handle boolean or floats too (and not all HTML types correspond to JS
types, like %) It would seem that most callers wouldn't need this extra
processing, and there's some bloat involved, so I'd lean towards keeping it
simple.  It's a relatively easy operation for the caller to do a type check
and the caller may wish to do the check anyways.


On Sun, Oct 19, 2008 at 5:00 PM, Mike Wilcox <mwilcox at sitepen.com> wrote:

> I'm working on a blog for SitePen on dojo.attr and dojo.style. I
> noticed that dojo.attr does not return a number. A number would be
> convenient for attributes like tabIndex or table.width.
> Through some light testing, it appears that adding something along
> these lines would work:
> if( parseInt(attribute) == Number(attribute) ){
>        return parseInt(attribute);
> }
> This seems to work in all the cases I can think of, although there are
> a ton of use cases for this, so I may be missing something that makes
> this a bad idea.
> The one exception I would think is if the attribute name were 'value'.
> Mike Wilcox
> mwilcox at sitepen.com
> http://www.sitepen.com
> work: 650.968.8787 x218
> cell:     214.697.4872
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at dojotoolkit.org
> http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-contributors/attachments/20081019/73ddb71f/attachment.htm 

More information about the dojo-contributors mailing list