opal
opal copied to clipboard
[wip] Mutable strings
tl;dr: How to implement mutable Strings while preserving compatibility
For boxed strings we are allowed to declare toString and valueOf properties on them. Not length though. So what if we made those methods actually return a different string?
This is an early work in progress.
The issue with this is that all String methods and alike should return a mutable string value and none of them do - which, on the other hand, is good for performance and JS library compatibility - JS libraries often check for typeof arg === 'string'
- and boxed strings would give us object
, not string
. Boxed values are in general a little known feature that some people think should be deprecated.
There are also a lot of issues with boxed values in JavaScript. Eg.
> "hello" === new String("hello")
false
> new String("hello") == new String("hello")
false
>