> I think we probably have an interesting question for Dave and Sam about how 
> to support version evolution of modules.  Is there a module equivalent of 
> monkey patching. What if we have an implementation that exposes a "V1" module 
> (particularly a built-in module) and code that depends upon upon a V2 of that 
> same module that has an expanded export list.  Is there anyway for that code 
> to patch the module to add the extra exported APIs it would like to use?

ES6 modules are not extensible, for a number of reasons including compile-time 
variable checking. But of course API evolution is critical, and it works; it 
just works differently. Monkey-patching says "let the polyfill add the module 
exports by mutation," e.g.:

    // mypolyfill.js
    ...
    if (!SomeBuiltinModule.newFeature) {
        load("someotherlib.js", function(x) {
            SomeBuiltinModule.newFeature = x;
        });
    }

you instead say "let the polyfill provide the exports," e.g.:

    // mypolyfill.js
    ...
    export let newFeature = SomeBuiltinModule.newFeature;
    if (!newFeature) {
        load("someotherlib.js", function(x) {
            newFeature = x;
        });
    }

The difference is that clients import from the polyfill instead of importing 
from the builtin module. I'm not 100% satisfied with this, but it's not any 
more code than monkey-patching.

Dave

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to