@pinoaffe Objects already capture their lexical scope upon creation. I'm unsure if there's code analysis happening to reduce the part of the scope that's retained (by identifying references).
@whreq @pinoaffe Ah, sorry, I misparsed the question, brain was occupied with something else.
You're correct that only *functions* capture their lexical scope, but aside from data-only objects (which can be treated specially and pretty much eliminate the need for such an $env feature in the first place), pretty much the only other thing that can exist on objects is functions, and so in practice "non-data objects capturing their scope" and "functions stored on objects capturing their scope" end up being approximately the same thing, differing only in implementation details.
If you wanted to be really specific you could make it func.$env.something instead, this would still address the sort of usecase I'm thinking of
@joepie91 @pinoaffe Do they? I thought only closures did that, and then only the variables that are actually used.