Re: Proposal: getStyleAs(property, primitiveValue)

On Tue, Dec 22, 2009 at 10:30 AM, Patrick Garies <pgaries@fastmail.us> wrote:
> On 9/22/2009 8:08 PM, Garrett Smith wrote:
>>>
>>> I also assume that getStyleAs can return a plethora of possible values
>>> from strings to other interfaces...
>>>
>>
>> I was thinking it would return a string although |asNumber| param
>> might a possibility:-
>>
>> x.getStyleAs("length", "px", "number");
>>
>> Returns a number representing the length, in css pixels.
>
> For some reason, I'm thinking Travis was wondering what all the types of
> returnable values are. So far, pixels, integers, and RGBA seem to be covered
> based upon your examples. |rgb| is also mentioned, but it's not clear if
> that's a reference to the hexadecimal or functional notation.
>
> The above code also seems overly complex IMHO. I can't tell what |"length"|
> is for. |x.getStyleAs("pxint")| or |x.getStyleAs("px", "int")| seem simpler;
> both output a pixel value as an integer. (I assume |x| is a reference to
> something like |element.style.margin| or am I mistaken?)
>

I think that x is someelement.style, and "lenght" is a just "a length
property" (for example margin-top, float-offset or font-size). In
fact, maintaing the invariant x.margin === "10px auto 10px auto" and
typeof x.margin === "string" was one of the reasons for getValueAs
instead of the simpler x.margin.px, which requires margin being an
object

Giovanni

Received on Tuesday, 22 December 2009 12:54:13 UTC