node index出錯.node 版本v0.12.2
root@tangyu-desktop:~/imooc/school# node index
/root/imooc/school/klass.js:1
tion (exports, require, module, __filename, __dirname) { requirevar student =?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ^^^^^^^
SyntaxError: Unexpected identifier
? ? at exports.runInThisContext (vm.js:73:16)
? ? at Module._compile (module.js:443:25)
? ? at Object.Module._extensions..js (module.js:478:10)
? ? at Module.load (module.js:355:32)
? ? at Function.Module._load (module.js:310:12)
? ? at Module.require (module.js:365:17)
? ? at require (module.js:384:17)
? ? at Object.<anonymous> (/root/imooc/school/index.js:1:75)
? ? at Module._compile (module.js:460:26)
? ? at Object.Module._extensions..js (module.js:478:10)
2015-04-20
你 klass.js 里面代碼寫錯了:
requirevar student 這里應(yīng)該是 var student 不應(yīng)該是前面多了個 require?
2015-04-20
teacher.js
function add(teacher):{
console.log('add teacher :'+teacher)
}
exports.add = add
student.js
function add(student):{
console.log('add student :'+student)
}
exports.add = add
klass.js
requirevar student = require('./student.js')
requirevar teacher = require('./teacher.js')
function add(teachername,students) {
teacher.add(teachername)
students.forEach(function(item,index) {
student.add(item)
})
}
exports.add = add
index.js
var klass = require('./klass.js')
klass.add('ty',['bfm','gfs'])