我一直在尝试学习callBack地狱,并试图复制,然后将它变成承诺。这是我的代码,--它在执行时的说法-- cb不是函数
我在这里所缺少的。
var t = addTwo(function(a, b) {
console.log(a * b);
divideTwo(function() {
console.log("arshita");
})
})
function addTwo(cb) {
cb(3, 4);
}
function divideTwo(cb1) {
}
addTwo();
发布于 2018-10-17 18:06:33
代码中有一个错误。
var t = addTwo(function(a, b) {
console.log(a * b);
divideTwo(function() {
console.log("arshita");
})
})
function addTwo(cb) {
cb(3, 4);
}
function divideTwo(cb1) {
}
addTwo((a, b) => a + b); // <----- Here you passed nothing, though `addTwo`
// expected a callback. I wrote an example callback that sums `a` and `b`更新
如果您想看看回调地狱是什么样子,那么看看这个(简单的,只有3级回调地狱):
function init(msg, cb) {
alert(msg)
cb()
}
function running(msg, cb) {
alert(msg)
cb()
}
function finish(msg) {
alert(msg)
}
// The below code may not be considered as "callback hell" yet, but add few more iterations and it definitely will become a hell
init('program started!', function() {
running('program is running', function() {
finish('program shut downs')
})
})https://stackoverflow.com/questions/52860951
复制相似问题