December 2018
Intermediate to advanced
642 pages
15h 5m
English
Before modules became widely available, there was a fairly common pattern in use, which basically provided the same features that today's modules do. First, let's introduce a sample fragment of code, and then examine its properties:
// Source file: src/iife_counter.js/* @flow *//* In the following code, the only thing that needs an explicit type declaration for Flow, is "name". Flow can work out on its own the rest of the types.*/const myCounter = ((name: string) => { let count = 0; const inc = () => ++count; const get = () => count; // private const toString = () => `${name}: ${get()}`; return { inc, toString };})("Clicks");console.log(myCounter); // an object, with methods inc and toStringmyCounter.inc(); // ...Read now
Unlock full access