[whatwg] Sample DOMTokenString Implementation

Lachlan Hunt lachlan.hunt at lachy.id.au
Tue Sep 6 17:51:07 PDT 2005

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

More information about the whatwg mailing list