Hacker News new | past | comments | ask | show | jobs | submit login

> dynamic import

Umm... you mean like AMD? Yeah, it's awesome (edit I mean, was a solved problem years ago). Somebody explain to me how people live without this.




AMD was a handy workaround, but better solutions exist now.

For one thing, each and every little module doesn't need to be written with knowledge of AMD or how it's going to be imported at all. If you used AMD with this component example, every single component you write would need to be wrapped in a `define()`. This has no wrapping, just standard JS exports.

Secondly, each module doesn't need to know its own name (to pass to the `define()` call), or even have a static name at all, it can effectively be anonymous & truly dynamic.

And finally, AMD modules make assumptions about the environment – for example, that you have control over `window.define`. If you're a third-party script trying to load things on someone else's website, good luck – you either just told someone else's module handler that you loaded, and have no visibility into it, or you clobbered the existing `window.define` and broke other people's scripts. (My former company's product was a third-party JS widget, and co-existing with dozens of other scripts and module loaders was a huge problem.)


These are all valid points... but I'm curious what you mean by "better solutions exist now." Basically everybody's agreed to use a transpiler for the foreseeable future [0]. How is that not a workaround?

[0] This is my first time to see that any browser has actually shipped ES6 modules: http://caniuse.com/#feat=es6-module




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: