我有一个情况,我想模拟一个函数,如果某些条件满足,我收到一个错误。javascript嘲笑原型函数错误
这里是有条件地选择是否嘲笑功能
MyClass.prototype.methodOne = function (callback) {
var self = this;
var methodTwo = this.methodTwo;
if (someCondition) {
methodTwo = function(callback) {
callback(null);
};
}
methodTwo(function (err) { });
}
MyClass.prototype.methodTwo = function (callback) {
var self = this;
var batch = new Batch();
batch.concurrency(this.options.concurrency); ----> error here
// some more stuff
callback(err);
}
的错误消息是Uncaught TypeError: Cannot read property 'concurrency' of undefined
如果不是调用methodTwo(function (err) { });
我打电话this.methodTwo(function (err) { });
一切正常功能。
您可以在您的示例中添加一些警报或console.log,并说明您的详细行为是什么? –