1、es6
export { a, b } 对应 import { a, b } from 'xxx'
export default name 对应 import name from 'xxx'
2、闭包模块化
var module = (function() {
var N = 5;
function print(x) {
console.log("The result is: " + x);
}
function add(a) {
var x = a + N;
print(x);
}
return {
description: "This is description",
add: add
};
})();
console.log(module.description); // 输出"this is description"
module.add(5); // 输出“The result is: 10”
let langUtil = {};
(function ($) {
$.getLang = function (lang, pageFlag) {
let langPackage;
...
return langPackage;
};
})(langUtil);
module.exports = langUtil;
// 获取
const langUtil = require('../lang/util');
const lang = langUtil.getLang(req.query.lang, productType);
网友评论