babel 转义,webpack压缩
mod.js
// 缺省导出类
export default class {
constructor(x) {
this.x = x;
}
show(){
console.log(this.x);
}
}
// 命名导出 函数
export function foo(){
console.log('regular foo()');
}
// 函数定义
function bar() {
console.log('regular bar()');
}
// 变量常量定义
let x = 100;
var y = 200;
const z = 300;
// 导出
export {bar, x, y, z};
index.js
// import defaultCls, {foo, bar, x, y, z as CONST_C} from './mod.js';
// foo();
// bar();
// console.log(x); // x只读,不可修改,x++异常
// console.log(y); // y只读
// console.log(CONST_C);
// new defaultCls(1000).show();
import * as newmod from './mod.js';
newmod.foo();
newmod.bar();
new newmod.default(2000).show();
测试babel
root@ubuntu:~/workspace/es6/babel# npx babel src -d dist/
Successfully compiled 2 files with Babel (213ms).
root@ubuntu:~/workspace/es6/babel# node dist/index.js
regular foo()
regular bar()
2000