- The Java lang arguments
- But some early attempts like Jaxer, Mozilla Rhino, etc.
- The same code on browsers, servers, microcontrollers, etc.
- ES3, ES5 or ES6/7 ?
- ES5 because of https://github.com/es-shims/es5-shim
- Missing block : module system
NO MODULES
- export to global context
Declaration :
var aja = {
awesome : function(){
console.log('awesome');
}
};
window.aja = window.aja || aja;
Usage :
window.aja.awesome();
- runs on node.js, io.js, browserify
Declaration :
var aja = {
awesome : function(){
console.log('awesome');
}
};
module.exports = aja;
Usage :
var aja = require('aja');
aja.awesome();
- require.js, almond, etc.
Declaration :
define([], function(){
var aja = {
awesome : function(){
console.log('awesome');
}
};
return aja;
});
Usage :
require(['aja'], function(aja){
aja.awesome();
});
- standard
Declaration :
var aja = {
awesome : function(){
console.log('awesome');
}
};
export default aja;
Usage :
import aja from 'aja';
aja.awesome();
(function(){
'use strict';
var aja = {
awesome : function(){
console.log('awesome');
}
};
//AMD
if (typeof define === 'function' && define.amd) {
define([], function(){ //don't name it
return aja;
});
//CommonJs
} else if (typeof exports === 'object') {
module.exports = aja;
//Old school
} else {
window.aja = window.aja || aja;
}
});
Or even better at https://github.com/umdjs/umd
But where are ES6 modules?
Imposible to feature detect (at least for now), see http://stackoverflow.com/questions/27922232/how-to-feature-detect-es6-modules
Building a generator that bundle the code for each system:
- a generic one (using UMD)
- AMD
- CJS
- Old School
- ES6
I am not going to maintain 5 versions of my source code So, automate it dude
Creation of a Grunt task : grunt-exportify