回调函数,其实可以这样理解:实现两个方法的链接,在一定程度上也很大程度上的缓解了,大型函数的场景,回调函数往往在异步的场景里用
loginService.login(params, this.SID, {
success: async (successResp) => {
let userInfo = successResp.Login;
}
errorResponse: (errorResp) => {
console.log(errorResp)
}
})
if (isFunction(success)) {
if (responseType !== 'json') {
success(responseData, resAttr);
} else {
success(responseData.Data, responseData, resAttr);
}
}
function callback(params) {
console.log("callback拿到的值", params) // callback拿到的值 kate 后打印
return params
}
function person(name,func) {
console.log("参数为",name) // 参数为 kate 先打印
func(name)
}
setTimeout(function() {
person('kate',callback)
}, 2000)