-
-
Save WebReflection/6002262 to your computer and use it in GitHub Desktop.
| function UMD(name, dependencies, factory) { | |
| // AMD | |
| if ('function' === typeof define && define.AMD) { | |
| define(name, dependencies, factory); | |
| } | |
| // node.js | |
| else if('object' === typeof exports) { | |
| module.exports = factory.apply( | |
| null, | |
| (dependencies || []).map(require) | |
| ); | |
| } | |
| // browsers / global | |
| else { | |
| Function('this.'.concat( | |
| name, | |
| '=f.apply(null,[', | |
| (dependencies || []).join(','), | |
| '])' | |
| ))(); | |
| } | |
| // how abour Rhino load ? ... maybe later on | |
| } |
The point is to meet all the tools where they are today w/o anything more than a transpile step, and then requiring nothing at all when es6 is supported.
This would require the transpile step to create a global UMD function, confirm? I don't think that's acceptable, and all we gain is a few bytes. Gzip saves us.
Also, I want to author in es6, and everybody has incentive to author in es6 modules because they are coming. Selling people on authoring with this UMD function is the same battle as just using AMD everywhere.
We have to agree on a module format, any proposal other than the spec will never fly. Then we transpile into formats that existing tools/environments understand already.
you are ssuming people will actually write ES6 soon ... that ain't realistic, so this is an alternative that does not require a transpiling step at all and best of all does not require developers writing a non final/standard/complete yet specification as it is for ES6, even if module are frozen (they are not)
We have to pick something, might as well be something that is going to be the spec (or close to it).
you are assuming people will actually write ES6 soon
I'm asking them to, yes :)
I actually made something like your gist: https://github.com/freezedev/udefine
While I've used this in some production apps, nowadays I rather want to write ES6 modules though :)
so you can ...