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