简体   繁体   中英

What is the difference between javascript Promise and q promise

Can they be interchanged? Are there any benifits in using q promise? Im new to promise world and i cannot find much help on internet for these questions!

Prior to the introduction of the global Promise constructor in ES6, promises were implemented in multiple code libraries, including q and others. The promises/A+ standard was developed to promote inter-operability between library code when more than one library was being used.

The A+ standard is not an easy read and perhaps aimed at developers more than promise users. Even so

  • ES6 Promises are A+ compliant
  • A+ compliance should guarantee that promises can be safely passed between compliant library versions of Promise used in the same project,
  • The A+ standard does specify how to handle non-standard promise implementations. As a result, ES6 and other A+ promises can handle promises from Jquery, but non standard promise implementations within Jquery can't handle being passed ES6 promises (a future version of Jquery is intended to be A+ compliant).
  • The A+ standard does not specify how to construct a promise, nor does it specify the global Promise methods Promise.all , Promise.race , Promise.resolve and Promise.reject .

If you are learning Promises, I would recommend starting with ES6/Javascript native promises because their interface with code has been standardized. Pollyfills are readily available if support is required in older browsers.

Other libraries may provide slightly different external code interfaces which you may need to become familiar with if you start to work on an existing project that uses one. Knowledge of ES6 promises will help speed up the process of understanding any particular library, including Q.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM