Hey guys,

What would it take to get block scoped prototype extensions into JavaScript? 
I’m curious to get some thoughts before I write a proposal.

The use case is similar to Scala’s block scoped implicits. In my application 
code I want Array.prototype.indexOf to return an Option<number>, rather than 
number | -1. If I patch Array’s prototype directly, it will break other 
libraries in my project. It would be nice to have a way to extend the prototype 
for just a block, or just a file.

Would a combination of block-scoped imports (maybe dynamic imports, to patch 
the prototype) and some sort of onExitBlock hook (to unpatch the prototype) be 
enough to implement this? Has anyone else thought about this sort of feature?

Boris
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to