일부 조건이 충족되고 오류가 발생하는 경우 함수를 모의하고 싶습니다. 여기 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);
}
대신 methodTwo(function (err) { });
를 호출 내가 this.methodTwo(function (err) { });
모든 것이 잘 작동 호출하면 오류 메시지가 Uncaught TypeError: Cannot read property 'concurrency' of undefined
인을 조롱 할 것인지 여부를 선택하는 기능입니다.
예를 들어 경고 또는 console.log를 추가하고 사용자의 행동이 무엇인지 말할 수 있습니까? –