在中間件中這麼寫:
wechat.reply.call(this);
在wechat中的reply函數是這麼寫的:
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
}
然後就報錯
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)
話說,call函數不是在原生js中就能用嗎,為什麼我在呼叫的時候報錯了呢?
而且,百度了一下,有這種錯誤的人特別少…
問大神:通常是什麼時候會報這個錯?報錯的原因是什麼?
舉個栗子
,就會報你遇到的錯誤🎜確認有 wechat.apply 這個方法🎜a.call(this,null)
,但是此時a
是undefined
,就會報你遇到的錯誤確認有 wechat.apply 這個方法麼
wechat實例應該沒有值,你在呼叫之前列印一下看看。
如果
x.call
中x
未定義,則其下的.call
無法訪問,所以你先確定一下wechat.reply
是否已經定義。另外,注意在JS中,變數名是區分大小寫的。