Ditch your global variables with this syntactic sugar
Transforms globals to implicit this expressions:
Before:
x = 10;
After:
this.x = 10;
$ npm install --save-dev babel-plugin-implicit-this
.babelrc
{
"plugins": ["implicit-this", { "env": "node", "globals": "./path/to/globals.json" }]
}
$ babel --plugins implicit-this script.js
const globals = {
foo_global: false
}
require("babel-core").transform("code", {
plugins: ["implicit-this", { env: 'browser', globals }]
});
MIT
- add
const self = this
at the top of instance methods