W3C home > Mailing lists > Public > www-style@w3.org > August 2011

Could CSSOM provide constructors and factory methods?

From: Dominic Cooney <dominicc@chromium.org>
Date: Wed, 10 Aug 2011 10:58:18 +0900
Message-ID: <CAHnmYQ8U9hRmNP4yaiBV-7J9XXtNLgsrquJiNTZ05ictBqAgUA@mail.gmail.com>
To: www-style@w3.org
The CSSOM seems to have a preponderance of parsing for creating objects. For
example, to create a MediaList, I bounce a string off a stylesheet:

s.media = 'print';
s.media  // MediaList appears!

What do you think about separating parsing, creation, and setting? For
example, applied to rules:

Specific CSS*Rule subtypes have Constructor(…) metadata.
insertRule is overloaded to accept CSSRule instances as well as DOMString.
Static CSSRule.parse(DOMString) can parse strings to produce CSSRules, so
you don’t have to abuse setters to do it.

Since there is not a detailed hierarchy for CSS values, maybe factory
methods instead of constructors make sense, so:

Static CSSPrimitiveValue.parse(DOMString)
Static CSSPrimitiveValue.px(unsigned int)

Having specific constructors and methods seems better than relying on
strings alone, because it is easier to find syntax errors (because mistyping
these result in JavaScript errors, which have stacktraces and tools support)
and it is easier to discern what the possible uses of a value are, whereas a
string could be anything.

Received on Wednesday, 10 August 2011 02:58:56 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:38:48 UTC