为了账号安全,请及时绑定邮箱和手机立即绑定

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

正在回答

1 回答

第一个报错应该是标点符号有错误,检查一下。第二个是你把this.words=words写成了this.works=works

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
进击Node.js基础(一)
  • 参与学习       219397    人
  • 解答问题       896    个

本视频教程带你揭开Node.js的面纱,带你走进一个全新世界

进入课程

dog不叫了,他报错!

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信