小编use*_*807的帖子

JavaScript中的"callback"关键字

请帮助理解以下代码:

// define our function with the callback argument

function some_function(arg1, arg2, callback) {
    // this generates a random number between
    // arg1 and arg2

    var my_number = Math.ceil(Math.random() * (arg1 - arg2) + arg2);

    // then we're done, so we'll call the callback and
    // pass our result
    callback(my_number);
}

// call the function
some_function(5, 15, function(num) {
    // this anonymous function will run when the
    // callback is called
    console.log("callback called! " + num);
});
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,回调关键字是什么.这个词的用法是什么.即使没有使用名称回调定义的函数.

javascript callback

8
推荐指数
2
解决办法
4621
查看次数

标签 统计

callback ×1

javascript ×1