27

I m trying to implement native promise on IE9+ and it seems that internet explorer does not Recognize the "Promise" class/object. I searched in http://caniuse.com/#search=Promise and saw that IE don't have Promise object. But this is strange because jQuery and Angular works with promises and working in IE9+. Maybe they are implementing their own Promise?? ** Can i implement my own promise ?**

user1019872
  • 649
  • 2
  • 9
  • 14
  • 1
    just search for a promise polyfill, like https://github.com/jakearchibald/es6-promise or https://github.com/taylorhakes/promise-polyfill – David Fregoli Jan 08 '15 at 08:21
  • 1
    [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) is not yet a standard. jQuery and Angular have their own implementation of promises and not necessarily functionally equivalent to Promise. Also "trying to implement native promise" is an oxymoron. :) – New Dev Jan 08 '15 at 08:24
  • http://stackoverflow.com/questions/23772801/basic-javascript-promise-implementation-attempt/ – guest271314 Jan 08 '15 at 15:58

2 Answers2

25

What's "native"

Being native means that it is written inside the browser's code base and not in user-level code. In order to implement promises natively in IE9 you'd have to obtain a copy of the IE9 source code from Microsoft, code those in, compile and distribute it. While that's doable that's not a very viable option.

Using promises today

On the other hand - there are several promise libraries that exist in userlevel. It's perfectly possible to implement your own promise implementation - here is a great blog post on how.

You can freely include a library like (bluebird) or Q that fulfill this API and will continue working well with ES6 promises in the future. It is worth mentioning that Bluebird for instance runs on IE6+ so there should be no issues in your case.

For example here is Angular's implementation and here is jQuery's implementation - Angular's is more readable in my opinion.

The standard

Also note that contrary to the coment left above promises are standardized by the Promises/A+ specification with libraries like Angular conform to and libraries like jQuery are working on conforming to and likely will in the next version. Native promises also conform to the standard and superset it.

Community
  • 1
  • 1
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
  • I have an application where I want promises to work in javascript. However, looking through the suggestions given here they only seem to give details for working in node.js. How do I get them working in javascript? I am already using promises in my javascript code. This works fine in Chrome, Edge etc. but I want this code to also work in IE. – Rachel Edge Feb 29 '16 at 11:19
  • Ah - it would help if I spelt the name of the javascript file correctly inside my script tag! It now works. – Rachel Edge Mar 01 '16 at 18:24
4

Here's a promise implementation I wrote myself in typescript, and is tested to fully work from IE8 upwards. Yes. it's fully Promises/A+ conformant (and tested).

Since it's written in typescript, the plan is to also get the definition up for tsd in the following days.

bogdan.mustiata
  • 1,725
  • 17
  • 26