Code Monkey home page Code Monkey logo

promise-yes's Introduction

Promise 的 N 种用法

这个标题是我临时起的,没想到站方直接拿来走宣传流程了……所以就不改了,就这么着吧。

开播时间:2017-04-06 20:00:00


内容简介

为解决异步函数的回调陷阱,开发社区不断摸索,终于折腾出来 Promise 这套方案。它不增加新的语法,可以适配当前的主流浏览器;写出来的代码也很好读懂;并且包含优秀的调试和捕获异常方案。在迭代中逐步完善,最终被吸收进 ES2015 规范。

现在大部分浏览器和 Node.js 都已原生支持 Promise,很多类库也开始返回 Promise 对象,即使面对 IE,也有各种降级适配策略。如果您现在还不会使用 Promise,那么我建议您尽快学习一下。

本次分享我准备结合近期的一些开发经验,总结一下 Promise 常见用法,介绍一下我踩过的坑。分享大纲如下:

  1. 什么是 Promise
  2. 为什么要用 Promise
  3. Promise 详解
  4. 简单范例
  5. 复杂加载过程
  6. 改进代码可读性
  7. 常见错误

分享长度:约1小时 分享难度:需要了解 JavaScript,最好有相关开发经验

范例代码

sample

协议

代码部分采用 MIT 进行许可。

知识共享许可协议 Slide 和文档部分采用 CC4.0 进行许可

promise-yes's People

Contributors

meathill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

dachengzi000

promise-yes's Issues

【修正】Promise N种用法-异步回调的问题-findLargest 解析

问题1:

因为回调函数和启动函数不在一个栈里,所以 try/catch 无法捕获到回调函数抛出的错误。于是回调函数只能用 callback(err) 的形式将错误反馈给启动函数。

问题2:

在外层作用域声明的变量,可能被其它函数访问和修改,造成错误。所以一般来说我们推荐哪里使用哪里声明。但是由于我们不清楚这些异步操作的完成顺序,只能在外层作用域声明变量。

问题3:

只有上面两个问题,没有标称的4个问题。


视频链接

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.