Re: Can't coerce to string
Tupshin Harper <[email protected]>
| Newsgroups | gmane.comp.java.xwt.core |
|---|---|
| Message-ID | <[email protected]> |
Adam Megacz wrote: >Brian Alliet <[email protected]> writes: > > >>I think if we follow ECMA-262's rules for Object.toString (that is, >>return a constant string in the form "[Object /classname/"], ie >>"[Object box]"). We shouldn't have any problems. Anybody who tries >>to use one of those strings as a key in a hashtable or something >>will quickly find out that they're doing something wrong. >> >> > >Er, see that's the problem... they won't find out quickly. If they're >accidentally concatenating a string somewhere along the way, then two >boxes will collide in the hash table. But what if it's some >rarely-used hash table and the developer never runs across a test case >that tries to insert two boxes? > >Nah, this is no good. > This works for three reasons: 1) The toString always returns a string that couldn't possibly be confused with something that could be used as a hash key 2) Whenever run in debug mode (which any ibex developer should do occasionally), they will get a warning that this is a Bad(tm) thing to do. 3) This is exactly how JS toString normally works. Yeah...this is good. -Tupshin