1.定义外部函数lib.js:
exports.showName = function(){
console.log('调用了showName函数');
}
还可以换另外一种写法:
function showName(){
console.log('调用了showName函数');
}
exports.showName = showName;
2.在index.js如何引用这个外部文件?
var getlib = require("./lib");
getlib.showName();
3.终端cd到项目目录下执行: $ node index.js 后,命令行输出:”调用了showName函数”。 表示OK。
2073

被折叠的 条评论
为什么被折叠?



