dog不叫了,他報錯!
var pet = { words: '...',?
speak: function(say) { console.log(say + ' ' +this.words) } }?
//pet.speak('Speak')
?var dog = { words: 'Wang' } pet.speak.call(dog,'Speak')
報錯:module.js:549? ? ?throw err;
function Pet(words) { this.works = works this.speak = function()?
{ console.log(this.words)
?}?
}?
function Dog(words) { Pet.call(this,words)?
//Pet.apply(this,arguments)
?}?
var dog = new Dog('Wang')?
dog.speak()
報錯:G:\nodejs\http\js\call_apply_extend.js:2 this.works = works ^ ReferenceError: works is not defined at Dog.Pet (G:\nodejs\http\js\call_apply_extend.js:2:15) at new Dog (G:\nodejs\http\js\call_apply_extend.js:9:6) at Object.<anonymous> (G:\nodejs\http\js\call_apply_extend.js:13:11) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16)G:\nodejs\http\js\call_apply_extend.js:2 this.works = works ^ ReferenceError: works is not defined at Dog.Pet (G:\nodejs\http\js\call_apply_extend.js:2:15) at new Dog (G:\nodejs\http\js\call_apply_extend.js:9:6) at Object.<anonymous> (G:\nodejs\http\js\call_apply_extend.js:13:11) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16)
是版本原因?
node v8.11.3
2018-08-14
第一個報錯應該是標點符號有錯誤,檢查一下。第二個是你把this.words=words寫成了this.works=works