回调函数
来源:互联网 发布:印度经济数据 编辑:程序博客网 时间:2024/06/15 08:41
ES5中使用回调函数
function fn(callBack) { // 回调函数 console.log("先执行A"); setTimeout(function () { callBack && callBack();//callBack存在并且callBack执行 }, 1000); } fn(function () { // 一个方法当作参数传递个另一个函数 console.log("在执行B"); });ES6中使用promise
function fn() { // 回调函数 console.log("66"); return new Promise(function (resolve, reason) { setTimeout(function () { resolve();//1s后执行 }, 1000); }) } fn().then(function () { console.log(77) })//函数fn()运行完后返回了Promise的实例
多次使用
function fn() { // 回调函数 console.log(666); return new Promise(function (resolve, reason) { resolve(); }) } fn().then(function () { console.log(777); return new Promise(function (resolve, reason) { // body resolve(); }) }).then(function () { // body console.log(888) })
阅读全文
0 0
- .NET 回调函数
- 回调函数
- 回调函数
- 回调函数概念
- 回调函数
- 回调函数
- 回调函数
- 回调函数 相关
- delphi 回调函数
- 回调函数
- 回调函数
- 回调函数学习
- 回调函数
- 关于回调函数
- 透析回调函数
- 回调函数
- 什么是回调函数
- 回调函数
- Python安装scipy,scikit-image时提示"no lapack/blas resources found"的解决方法
- [Leetcode] 159. Longest Substring with At Most Two Distinct Characters 解题报告
- Ubuntu16.04 vm tools安装方法及遇到的问题详解
- LeetCode:House Robber
- G4.9pool alloc用例
- 回调函数
- 用友U8手工清除工作流资料
- UDOO X86比Raspberry Pi性能强10倍 Windows/Linux/Android通吃
- Java标识符的命名方法
- Template by 2015ljn
- Angular常见面试题
- 【算法题】链表归并排序
- 机器学习十大算法--SVM(支持向量机)
- 排序算法之快速排序<Quick_Sort>及其C语言代码实现