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?
For example,
a.call(this,null)
, but at this timea
isundefined
, the error you encountered will be reportedHave you confirmed that there is a wechat.apply method?
The wechat instance should have no value, please print it before calling.
If
x
inx.call
is not defined, the.call
under it cannot be accessed, so you should first make sure whetherwechat.reply
has been defined.Also, note that in JS, variable names are case-sensitive.