W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2005

[whatwg] Sample DOMTokenString Implementation

From: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Date: Wed, 07 Sep 2005 10:51:07 +1000
Message-ID: <431E397B.4060204@lachy.id.au>
Erik Arvidsson wrote:
> You are really misusing new here. You never return an object of type 
> DOMTokenString. Since all your methods are linear and return a new 
> string you might as well implement them on the String prototype object.

Well, yes, and in fact, when implementing the final version so that 
Element.className.add(), etc. can be used, I'll probably just have to 
extend the string prototype anyway.  It would cetainly be more efficient 
than creating a new string and adding the methods each time, but I 
wasn't sure if all strings should implement the interface.

> Lachlan Hunt wrote:
>>     s = s.add("baz quux") // returns "foo bar foo baz quux"
> Shouldn't this raise an exception?

It could raise a DOMException SYNTAX_ERR [1], but what's wrong with just 
accepting it?


Lachlan Hunt
Received on Tuesday, 6 September 2005 17:51:07 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:24 UTC