Sharing objects across modules (was: VirtualHandler fundamental traps default values)
2012/9/11 David Bruant <bruant.d at gmail.com>
Le 11/09/2012 21:14, Tom Van Cutsem a écrit :
(...) Note that in ES6, Reflect should probably be represented as a module instance, not as a global object. So then Handler.prototype would inherit from a module instance object. I don't see anything necessarily wrong with that, but I just want to point it out. Is there a value to instanciate the Reflect module several times? So far, it's only made of stateless methods, it would save memory to have only one Reflect object in my opinion.
The Reflect module is indeed stateless. And IIRC, module instances would be frozen anyway.
I don't know the exact rules of module instance objects. Is it possible to reify the same module as multiple distinct instance objects in the same module loader context, or does the loader context cache a single instance object per module?
On Tue, Sep 11, 2012 at 3:44 PM, Tom Van Cutsem <tomvc.be at gmail.com> wrote:
I don't know the exact rules of module instance objects. Is it possible to reify the same module as multiple distinct instance objects in the same module loader context, or does the loader context cache a single instance object per module?
The latter -- there should be only one instance.
I think it cachês a single instance object per module.
I´ve never got the same module for multiple objects.
If someone got it, please let me know.
,
Marcos
Le 11/09/2012 21:14, Tom Van Cutsem a écrit :
Is there a value to instanciate the Reflect module several times? So far, it's only made of stateless methods, it would save memory to have only one Reflect object in my opinion.
If modules aren't the tool to share a single object across other modules, what is such a tool? Because it seems to be a valid use case. Likewise for the same of interoperability, if there is an @handler module, it ought to be a unique function (otherwise, two instances of two different @handler constructors do not share the same prototype).