//student.js
function add(student) {
console.log(student);
}
exports.add = add;
.................................................................................(分割線)
//teacher.js
var student=require('./student');
function add(teacher) {
console.log(teacher);
}
student.add('小明');
add('張老師');
而控制台的錯誤提示:
TypeError: student.add is not a function
at Object. (D:\LearnTools\Sublime Text 3x64\Project\Nodejs-test\s
chool2\teacher.js:9:9)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:146:18)
at node.js:404:3
我用nodejs環境試驗了沒有錯
可能是你的漢字編碼把
你試試把這個文件的編碼弄成utf-8
然後再把
//student.js這些沒用的注釋刪除掉
就ok 了