background preloader

Modular JavaScript

Facebook Twitter

Une plongée illustrée dans les modules ECMAScript. Les modules ECMAScript (ou modules ES) sont un système de modules, standard et officiel, pour JavaScript. Ce système est le fruit d’un travail de standardisation qui a duré 10 ans. Nous pourrons bientôt profiter de tout cela avec l’arrivée des modules dans Firefox 60 en mai (cette version est actuellement en bêta). Les navigateurs principaux prennent tous en charge cette fonctionnalité et le groupe de travail pour les modules Node contribue à l’ajout des modules ES dans Node.js. Previewing ES6 Modules and more from ES2015, ES2016 and beyond. Chakra, the recently open-sourced JavaScript engine that powers Microsoft Edge and Universal Windows applications, has been pushing the leading edge of ECMAScript language support.

Previewing ES6 Modules and more from ES2015, ES2016 and beyond

Most of ES2015 (aka ES6) language support is already available in Edge, and last week’s Windows Insider Preview build 14342 brings more ES6 capabilities including modules, default parameters, and destructuring. We’re not stopping there – Edge also supports all ES2016 (aka ES7) proposals – the exponentiation operator and Array.prototype.includes – as well as future ECMAScript proposals such as Async Functions and utility methods like Object.values/entries and String.prototype.padStart/padEnd.

Une plongée illustrée dans les modules ECMAScript - Bidouilleux d'Web. 16. Modules. 16.1.

16. Modules

Overview 16.1.1. ES modules: A cartoon deep-dive - Mozilla Hacks - the Web developer blog. ES modules bring an official, standardized module system to JavaScript.

ES modules: A cartoon deep-dive - Mozilla Hacks - the Web developer blog

It took a while to get here, though — nearly 10 years of standardization work. But the wait is almost over. Anodynos/uRequire: The Ultimate JavaScript Module Builder & Automagical Task Runner. Convert AMD & CommonJS/NodeJS modules to UMD, AMD, CommonJS or bundle them as `combined.js` (rjs & almond, AMDclean soon) & automagically run/test/watch them on. uRequire: JavaScript Universal Module & Resource Converter: convert modules from AMD to nodejs, commonjs and back, to UMD, to plain script .js. UMD: JavaScript modules that run anywhere. This is not about RequireJS, and ultimately has very little to do with it at all.

UMD: JavaScript modules that run anywhere

I'm not here to discuss whether or not RequireJS is something you should be using for your JavaScript projects...that's really up to you. There are a lot of projects out there that use RequireJS, and there are a lot that don't. With that disclaimer out of the way, I will say this about RequireJS...I've wrestled with it enough that it has had the positive side-effect of forcing me to figure out how to write my JavaScript modules in such a way that I can develop and test them without RequireJS, while still making them compatible for use in projects that use RequireJS without needing to shim it...and even elsewhere if/when necessary or helpful.

Universally compatible code In the context of JavaScript, UMD stands for Universal Module Definition. What I will do here is describe how the learning the concept has helped me. Managing dependencies Sigh... Here's an example of how I applied it to one of my side projects. Umdjs/umd. A 10 minute primer to JavaScript modules, module formats, module loaders and module bundlers. Modern JavaScript development can be overwhelming.

A 10 minute primer to JavaScript modules, module formats, module loaders and module bundlers

When working on a project, you may wonder why all the modern machinery and tooling is needed. What are tools like Webpack and SystemJS doing? Or what do AMD, UMD or CommonJS mean? A history of different JavaScript module formats. CommonJS: JavaScript Standard Library. What is AMD, CommonJS, and UMD? Intro Over the years there’s been a steadily increasing ecosystem of JavaScript components to choose from.

What is AMD, CommonJS, and UMD?

The sheer amount of choices is fantastic, but this also infamously presents a difficulty when components are mixed-and-matched. And it doesn’t take too long for budding developers to find out that not all components are built to play nicely together. To address these issues, the competing module specs AMD and CommonJS have appeared on the scene, allowing developers to write their code in an agreed-upon sandboxed and modularized way, so as not to “pollute the ecosystem”. Asynchronous Module Definition (AMD) has gained traction on the frontend, with RequireJS being the most popular implementation.

Here’s module foo with a single dependency on jquery: And a little more complicated example with multiple dependencies and multiple exposed methods: Note that the dependency to variable order is important (ex. jquery->$, underscore->_). Writing Modular JavaScript With AMD, CommonJS & ES Harmony. When we say an application is modular, we generally mean it's composed of a set of highly decoupled, distinct pieces of functionality stored in modules.

Writing Modular JavaScript With AMD, CommonJS & ES Harmony

As you probably know, loose coupling facilitates easier maintainability of apps by removing dependencies where possible. When this is implemented efficiently, its quite easy to see how changes to one part of a system may affect another. Unlike some more traditional programming languages however, the current iteration of JavaScript (ECMA-262) doesn't provide developers with the means to import such modules of code in a clean, organized manner. It's one of the concerns with specifications that haven't required great thought until more recent years where the need for more organized JavaScript applications became apparent. Instead, developers at present are left to fall back on variations of the module or object literal patterns.

RequireJS

Tylermcginnis.