explaingit

stefanpenner/es6-promise

7,274JavaScriptAudience · developerComplexity · 1/5Setup · easy

TLDR

A polyfill that adds Promise support to older browsers and environments that do not have it built in, so you can write modern async JavaScript that still works in Internet Explorer and other legacy targets.

Mindmap

mindmap
  root((es6-promise))
    What it does
      Promise polyfill
      Legacy browser support
    Variants
      Standard build
      Auto-patch build
    Install options
      npm
      yarn
      CDN script tag
    Use cases
      IE compatibility
      Old Node versions
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Use modern Promise-based async code in a project that must still support old browsers like Internet Explorer 11.

USE CASE 2

Patch the global Promise object automatically at app startup so all existing code in a Node.js app works without changes.

USE CASE 3

Include a minified CDN build on a legacy webpage to enable async patterns without a build step.

Tech stack

JavaScript

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

es6-promise is a polyfill for the Promise feature in modern JavaScript. A polyfill is a piece of code that adds a feature to older environments that do not have it built in. Promises are a way of writing asynchronous code, meaning code that deals with tasks that take time, such as network requests, without blocking everything else while waiting. They let you describe what should happen when a task succeeds or fails, in a cleaner style than older callback patterns. This library was particularly useful in the years when older browsers and older versions of Internet Explorer did not support Promises natively. Including it meant your code could use the standard Promise syntax and still work on those older environments. There are two main build variants: the standard one, where you load it and refer to it explicitly in your code, and the auto variant, which automatically replaces or adds the global Promise object if it is missing or not working correctly. Installation works through npm or yarn, and you can also load it directly in a webpage via a CDN script tag. There are minified versions of both variants for production use. For Node.js you import it and refer to its Promise export, or call a polyfill method once at startup to patch the global environment for your whole application. The README notes a quirk for very old Internet Explorer versions where the words catch and finally are reserved keywords that cause a syntax error when used as method names in dot notation. The workaround is to use bracket notation instead, though most code minifiers fix this automatically. The library is a focused subset of a larger library called rsvp.js and does not include the extra debugging and inspection features that the full library provides.

Copy-paste prompts

Prompt 1
I need to use Promises in a web project that must support Internet Explorer 11. Show me how to include es6-promise and wire it up so the global Promise is available everywhere.
Prompt 2
How do I use the es6-promise auto variant to patch the global Promise object in a Node.js application at startup with a single call?
Prompt 3
In es6-promise, how do I call .catch() on Internet Explorer without hitting the reserved keyword syntax error?
Open on GitHub → Explain another repo

← stefanpenner on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.