node.js - Nodejs报错Cannot read property 'call' of undefined
PHP中文网
PHP中文网 2017-06-29 10:09:20
0
3
1350

Write this in the middleware:
wechat.reply.call(this);
Write the reply function in wechat like this:

Wechat.prototype.reply = function(){
    console.log('bbbbb');
    var content = this.body;
    var message = this.weixin;
    var xml = util.tpl(content,message)

    console.log(xml);
    this.status = 200
    this.type = 'application/xml'
    this.body = xml
    return
}

Then an error is reported

TypeError: Cannot read property 'call' of undefined
      at Object.<anonymous> (C:\www\koa\wechat\wechat\g.js:54:16)
      at Generator.next (<anonymous>)
      at onFulfilled (C:\www\koa\wechat\node_modules\co\index.js:65:19)
      at process._tickCallback (internal/process/next_tick.js:109:7)
      

By the way, isn’t the call function available in native js? Why did I get an error when I called it?

Moreover, after searching on Baidu, there are very few people with this error...
Ask the master: When does this error usually occur? What is the reason for the error?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
大家讲道理

For example, a.call(this,null), but at this time a is undefined, the error you encountered will be reported
Have you confirmed that there is a wechat.apply method?

女神的闺蜜爱上我

Writing like this in the middleware:
wechat.reply.call(this); writing the reply function in wechat like this:

The wechat instance should have no value, please print it before calling.

console.log(wechat.reply)
刘奇

If x in x.call is not defined, the .call under it cannot be accessed, so you should first make sure whether wechat.reply has been defined.
Also, note that in JS, variable names are case-sensitive.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template