nodejs微信公众号出现 Cannot read property 'call' of undefined


var wechat = new Wechat(opts);
//console.log('---------wechat.reply-------');
//console.log( wechat.reply);
  wechat.reply.call(this);
  
  
Wechat.prototype.reply = function () {
var content = this.body;
var message = this.weixin;

var xml = util.tpl(content,message);

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

};
出现这样的错误
TypeError: Cannot read property 'call' of undefined

实例方法也有,为什么会出现这样的错误呀

阅读 2.8k
2 个回答

调用函数的代码,写在定义的后面,也就是说下面的两行代码放到最后

var wechat = new Wechat(opts);
wechat.reply.call(this);

再写清楚点吧:

Wechat.prototype.reply = function () {
var content = this.body;
var message = this.weixin;

var xml = util.tpl(content,message);

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

// 这个位置调用!
var wechat = new Wechat(opts);
wechat.reply.call(this);
新手上路,请多包涵

老哥 你怎么解决的呀 我现在也是在这里卡住了
打印wechat有值 但是wechat.replay就是undefined了 图片描述

图片描述

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题