Universal Module Definition (UMD)

We saw three different specifications for implementing modules. These three specifications have their own respective ways of creating and importing modules. Wouldn't it be great if we could create modules that were imported as an IIFE, AMD, or CommonJS module?

UMD is a set of techniques that are used to create modules that can be imported as an IIFE, CommonJS, or AMD module. Therefore, now a program can import third-party modules, irrespective of what module specification it is using.

The most popular UMD technique is returnExports. According to the returnExports technique, every module needs to be represented by a separate file. So, let's create a file named math.js that represents a module. Here is the ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.