zl程序教程

您现在的位置是:首页 >  后端

当前栏目

【说站】js中可选的回调函数

JS 函数 回调
2023-06-13 09:13:23 时间

js中可选的回调函数

1、then的回调函数不是严格要求必写的。如果不写,promise也会用上一个返回的最终值来传递。

doSomething().then().then(function(result) {
  console.log('got a result', result);
});
 
// 输出结果是:
//
// got a result 42

2、如果当前的then没有传输回调函数,该函数将直接使用前一个promise返回的最终值来解决下一个promise。

if(!handler.onResolved) {
  handler.resolve(value);
  return;
}

以上就是js中可选的回调函数,希望对大家有所帮助。更多js学习指路:js教程

收藏 | 0点赞 | 0打赏