Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lesson5中callback求解 #136

Open
gruad opened this issue Jun 1, 2017 · 6 comments
Open

lesson5中callback求解 #136

gruad opened this issue Jun 1, 2017 · 6 comments

Comments

@gruad
Copy link
Contributor

gruad commented Jun 1, 2017

    setTimeout(function () {
        concurrencyCount--;
       // callback为什么这么写?两个参数,我小白看不懂啊,求解
        callback(null, url + ' html content');
    }, delay);

callback是什么?是函数吗?看不懂,真心求解(看到是从主函数fetchUrl(url,callback)中传过来的)

@joshinrai
Copy link

joshinrai commented Jun 1, 2017 via email

@xdoer
Copy link

xdoer commented Jun 5, 2017

你打印一下这个callback函数看看是什么啊。。
function (err, v) { results[x.index] = v; callback(err); }.
把这函数带进去就能看懂了

@yuk320
Copy link

yuk320 commented Jun 7, 2017

callback是回调函数 用于将函数当参数传进去并将结果返回出来的方法,主要用于异步操作时应对非同步响应结果。
callback 你可以理解为一个 变量
你赋值时 可以 赋予一个 Function
callback(null,url + ' html content');
当 callback = function(err, content) 时 传回的第一个参数为 err 第二个参数为 content

@yanbo0039
Copy link

咦。。。这么热闹

@xwHoward
Copy link

这个是async#mapLimit的规定写法,我最开始看也是很疑惑mapLimit怎么知道这些异步函数什么时候执行完,后来仔细看了asyncAPI才知道是必须声明这个名为callback的回调,在异步操作完成时调用,并且第一个参数是null(执行无错时)或者error(出错时)。

@XiongJingzhi
Copy link

mapLimit(arr, limit, iterator, callback),iterator里面的callback就是后面的callback,callback参数result是一个iterator里面callback参数的数组。相当于fuck(arguments)参数的伪数组。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants