node.js - Nodejs报错Cannot read property 'call' of undefined

查看:395
本文介绍了node.js - Nodejs报错Cannot read property 'call' of undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

在中间件中这么写:
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.reply.call(this);在wechat中的reply函数是这么写的:

wechat实例应该没有值,你在调用之前打印一下看看。

console.log(wechat.reply)

这篇关于node.js - Nodejs报错Cannot read property &#039;call&#039; of undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆