babel --modules=umd es6.js
if (typeof define === 'function' && define.amd) {
define(['exports', 'module'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module);
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod);
global.smartbanner = mod.exports;
}
以上代码的结果会把 class 名字变为小写,global 下。
这是有什么规范吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
= = 难道没人碰到过吗
babel 转换后的代码你不要去管它,本来构造函数大写只是代码风格上的约定,并非解释器强制的约束,所以对于代码的执行并不会有任何影响。babel 对 es6 做转化只是过渡时期的措施,一旦浏览器对新的语法支持跟进到位,babel 也会 moving forward to es next,如果浏览器直接理解你的 class 了,还需要 babel 做这个事儿吗?