You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 第三个参数就是回调函数functionfunc1(param1,param2, ...,callback){// To do some action// 往往会在最后调用 callback 并且传入操作过的参数callback(cbParam1,cbParam2, ...)}// 实际调用的时候func1(param1,param2, ...,(cbParam1,cbParam2, ...)=>{// To do some action})
Activity
tiyunchen commentedon Jun 1, 2019
通常将一个函数B传入另一个函数A,并且在 需要的时候再调用函数A。
promise 就有回调
myprelude commentedon Jun 13, 2019
Damon99999 commentedon Jun 18, 2019
AricZhu commentedon Jun 19, 2019
回调函数就是指函数在初始定义的时候先不执行,等满足一定条件以后再拿出来执行。如下:
setTimeout(() => { console.log('在本轮任务最后执行!') }, 0);
persist-xyz commentedon Jun 29, 2019
Konata9 commentedon Jul 6, 2019
回调函数首先作为一个函数的参数传入,当这个函数执行后再执行的函数,往往会依赖前一个函数执行的结果。
在
javascript
中,对于 I/O、HTTP 请求等异步操作,为了控制执行的顺序就需要使用回调的方法。当有过个任务需要顺序执行时,如果采用回调函数的形式就会出现我们熟悉的“回调地狱”的情况。为了解决这个问题,在 ES6 中就有了
Promise
和async/await
方法。目前看来
async/await
在异步写法上较为优雅。15190408121 commentedon Jul 13, 2019
简单的这个算吗
var i = 0;
function callBack(I) {
if (I < 10) {
console.log(i)
callBack(i++)
} else {
console.log("回调成功")
}
}
callBack(i)
Vi-jay commentedon Jul 25, 2019
不算 你这是递归
Vi-jay commentedon Jul 25, 2019
hc951221 commentedon Aug 7, 2019
function a() {
console.log('触发了函数a')
}
function b() {
console.log('触发了函数b')
}
function c(callback1, callback2) {
let num = Math.random() * 10
if (num > 6) {
callback1()
} else {
callback2()
}
}
c(a,b)
15190408121 commentedon Aug 25, 2019
// 比较简单的就是快排算法
function quick(arr) {
if(arr.length <= 1) {
return arr; //递归出口
}
var left = [],
right = [],
current = arr.splice(0,1); //注意splice后,数组长度少了一个
for(let i = 0; i < arr.length; i++) {
if(arr[i] < current) {
left.push(arr[i]) //放在左边
} else {
right.push(arr[i]) //放在右边
}
}
return quick(left).concat(current,quick(right)); //递归
}
xcLtw commentedon Sep 2, 2019
[1,2,3].map(x=>x+1)
按照依赖前置函数,作为参数传入的条件,这个是回调函数吧
Yulingsong commentedon Sep 25, 2019
不知道这个算不算,以前对请求方法做了一个简化,success和error算是回调函数吧,我的理解就是把函数当做参数放到另一个函数中。。
25 remaining items