- From: Dominic Cooney <dominicc@google.com>
- Date: Wed, 10 Aug 2011 10:57:18 +0900
- To: www-style@w3.org
- Message-ID: <CAHnmYQ-vbCbecBNfyd0e8M3CCrH+T_tNBEdK4Me_P6+wdUQK_w@mail.gmail.com>
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) etc. 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. Dominic
Received on Wednesday, 10 August 2011 01:57:41 UTC