W3C home > Mailing lists > Public > public-svg-ig@w3.org > April to June 2009

RE: explaining baseVal and SVG DOM

From: Dailey, David P. <david.dailey@sru.edu>
Date: Wed, 15 Apr 2009 06:57:36 -0400
Message-ID: <1835D662B263BC4E864A7CFAB2FEEB3D0225DB8C@msfexch01.srunet.sruad.edu>
To: Erik Dahlström <ed@opera.com>, "SVG IG List" <public-svg-ig@w3.org>
Thanks Erik!

It makes sense to me now. 


-----Original Message-----
From: Erik Dahlström [mailto:ed@opera.com] 
Sent: Wednesday, April 15, 2009 6:50 AM
To: Dailey, David P.; SVG IG List
Subject: Re: explaining baseVal and SVG DOM

On Fri, 10 Apr 2009 18:40:17 +0200, Dailey, David P. <david.dailey@sru.edu> wrote:

> In working through Erik D's comments upon the book I'm working on, he
> observes how an
> alternative to document.getElementById("R").getAttribute("height") might
> be document.getElementById("R").height.baseVal.value
> I confess to being a bit ignorant of any reasons for preferring or not
> the use of baseVal, but am considering including text such as the
> following to describe the situation:

The difference is that getAttribute returns a DOMString, and height.baseVal.value returns a float. Now, the conversion between string and float may not be such an issue in most cases, but if you do it often then those extra float <-> string conversions can become costly.

Another proposal that the SVG WG has discussed is to make e.g rect.height be essentially the same as rect.baseVal.height.value. Then you could write things like this:

circle.cx = 4; // float assignment
circle.cy = "2em"; // string assignment (sets unit and value as if valueAsString had been assigned to instead)
alert(circle.cx); // alerts whatever cx stringifies as (e.g "2em" or "4")
var diameter = circle.r * 2; // should get the float value


Erik Dahlstrom, Core Technology Developer, Opera Software
Co-Chair, W3C SVG Working Group
Personal blog: http://my.opera.com/macdev_ed
Received on Wednesday, 15 April 2009 10:58:55 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:28:24 UTC