未加星标

JS: Promises/A+ and. jQuery history

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二04 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

In mylast post I listed a bunch of confusing things about promises. That time I clarified “deferred” and “promise” and this time I’ll start writing about Promises/A+ and jQuery’s promises.

Promise or promise?

The concept of a promise has been around for a long time ( 1976 in fact). Promises/A+ and jQuery’s promises are both implementations of the promise concept. They both represent future values and both simplify programming with async operations.

So how’d we get two of the same thing?

Well, they’re not actually the same thing, but we’ll briefly talk about the history first.

Why do we have two?

JS got promises with ECMAScript 6, which is slowly making it’s way into browsers . But before the spec was settled (see what I did there?) jQuery got to work on an implementation. jQuery knew browsers weren’t going to support promises right away, and, as with other shiny new JS, developers would have to rely on a library or polyfill to use the new features. (Other libraries knew this as well and did similar things to jQuery, but jQuery is the most common, so we’re talking about it.)

I like to think it went something like this:

Developers:We’d like to use promises in JS

JS spec:Hmmm, interesting idea... yeah, let’s do that

jQuery: typing, developing, debugging

JS spec:But how? Let’s really think about what should happen.

jQuery: typing, developing, debugging

JS spec: Debating, email threads, thinking

jQuery:Here you go!

JS spec: Debating, email threads, thinking

Developers:Thanks jQuery, we’ll get right on it!

JS spec:Here’s the theoretical description of what should happen.

jQuery, developers, and JS spec:Well this is awkward.

So before the official JS specification for promises (eventually called Promises/A+) had landed we had an implementation for promises in jQuery. This was super handy for developers then since it meant they could have all the advantages of promises as soon as jQuery allowed it. The problem is that jQuery’s implementation and Promises/A+ differ. And it’s not likely that either will change any time soon.

With a bit of effort jQuery’s promises and Promises/A+ can play nicely together, but that effort wasn’t made in the past since the Promises/A+ weren’t even available at the time. There’s also the mental effort involved in knowing both ways of working with the promises and knowing what type of promise you’re working with at any given time.

It’s not ideal, but it’s the world we live in.

Next time we’ll talk about the differences between the Promises/A+ spec and jQuery’s implementation of promises so you know what to watch out for.

Did you find this post helpful? Please share it!

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: jQueryECMAScript
分页:12
转载请注明
本文标题:JS: Promises/A+ and. jQuery history
本站链接:http://www.codesec.net/view/521483.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(60)