opal icon indicating copy to clipboard operation
opal copied to clipboard

[wip] Mutable strings

Open hmdne opened this issue 2 years ago • 1 comments

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.

hmdne avatar Nov 12 '21 03:11 hmdne

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
> 

hmdne avatar Nov 14 '21 06:11 hmdne