模块化:把一些公共js函数抽离出来使用
使用model.exports来暴露模块接口
// common.js function sayHello(name) { console.log(`Hello ${name} !`) } function sayGoodbye(name) { console.log(`Goodbye ${name} !`) } module.exports.sayHello = sayHello exports.sayGoodbye = sayGoodbye
如果在其他文件中引用:使用require
var common = require(\'common.js\') Page({ helloMINA: function() { common.sayHello(\'MINA\') }, goodbyeMINA: function() { common.sayGoodbye(\'MINA\') } })