Re: DOMString-like objects for the CSSOM

On Fri, Feb 19, 2010 at 6:57 AM, Anne van Kesteren <annevk@opera.com> wrote:

> For the CSSOM the CSS WG has an idea on how we can extend the current
> string-based interface to CSS property values to become an object-based
> interface in a mostly backwards compatible way.
>
> The way this would work is that the attributes on the CSSStyleDeclaration
> interface (you can get access to an object implementing that interface
> through e.g. document.body.style) no longer return a DOMString but a
> DOMString-like object. This DOMString-like object has all the functionality
> of DOMString but also supports additional features. E.g. in the case of a
> CSS color property it would have red/green/blue/alpha members that allow
> reading and direct manipulation of various aspects of the color value.
>
> I wondering whether there was some shorthand that we could introduce in Web
> IDL for this. E.g. allow an interface to inherit from DOMString. Thoughts?
>

DOMString is WebIDL shorthand for string, not for String. Unless you are
proposing a new primitive string-like data type be added to JS -- which
should be about as fun as adding decimal as a new primitive numeric type --
then your new DOMString-like data type would be WebIDL shorthand for a
String-like data type, which isn't string-like at all. Mapping backwards, it
would therefore not be DOMString-like, no matter what WebIDL might claim to
the contrary. For example, is the ! of an empty DOMString-like object true
or false?

This is yet another example of why WebIDL is a bad language for designing
JavaScript APIs. The choices encouraged by WebIDL, and that seem natural in
WebIDL, often result in bad JavaScript API designs.


>
>
> --
> Anne van Kesteren
> http://annevankesteren.nl/
>
>


-- 
    Cheers,
    --MarkM

Received on Friday, 19 February 2010 15:26:17 UTC