|
|
|
|
|
by uncleyo
1838 days ago
|
|
I wonder if JS could benefit from a system similar to Rust editions (https://doc.rust-lang.org/edition-guide/introduction.html). Requiring assertion like "This code was written in 2021, no MooTools here" seems like a reasonable ask to access new features in the standard library. I know it may sound similar to what X-UA-Compatible did, but that was really horribly implemented and vendor specific... |
|
What Rust does about this specific problem is that nobody else gets to mess with your stuff. For the exceptional case of the built-in types the core and I believe also std (the standard library) are allowed to define things for those types but nobody else can.
So you can't add an is_stupid() const boolean method for the char built-in that classifies Unicode scalar values by whether they are (in your opinion) stupid or not.
You could invent your own trait named Stupid with the is_stupid() method, and you can implement that trait on the built-in char type, but only people who explicitly want your Stupid trait get this behaviour. They aren't infected just by happening to use some other features you implemented.