Has there ever been an proposal for a way to modify JavaScript prototypes only inside modules where it's explicitely declared? Basically as in Kotlin Extensions?
http://kotlinlang.org/docs/reference/extensions.html …
Is there an obvious reason this would be a bad idea?
@wycats @domenic @bterlson
I think we'd want to define it so that the extensions "win" and can't be changed. This would mean that if you get a hit by the time you're JITing, you can rely on the hit remaining stable.
-
-
That's a minor thing. You still need to intercept every o.x because of could be one of these prototypes (assuming that x was listed in the extensions). And even worse every o[k] because k could evaluate to a property key in the extension list.
-
Not saying it's not doable, but it comes at a cost.
-
Something in common among the other languages I amdon't aware of which support extensions is that they can be resolved more or less statically
-
Right. I think if we did this we would want very static resolution. I think that's a fair constraint.
-
Incidentally, Ruby's "refinements", which are this feature, are pretty static but could have been more static (and would have been better for it).
-
Static sounds good from the VMs perspective. Not sure how useful that is in the JavaScript world tho.

-
If it's not static, it becomes very hard to understand. I participated a lot in the Ruby version of this conversation and became very convinced that the feature is more useful when static because it can be understood more easily.
-
I can't really speak to that since I don't have the same background as you have, but I find your argument very convincing.

- 3 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.