LINUX.ORG.RU

История изменений

Исправление javascript, (текущая версия) :

В той же статье на mdn, в одном из примеров демонстрируется, как создаются замыкания на скоуп IIFE

The shared lexical environment is created in the body of an anonymous function, which is executed as soon as it has been defined (also known as an IIFE). The lexical environment contains two private items: a variable called privateCounter, and a function called changeBy. You can’t access either of these private members from outside the anonymous function. Instead, you can access them using the three public functions that are returned from the anonymous wrapper.

Those three public functions are closures that share the same lexical environment. Thanks to JavaScript’s lexical scoping, they each have access to the privateCounter variable and the changeBy function.

Посему, если ты хочешь избавиться от противоречий, то просто воспринимай module\block scope как частный случай IIFE. Они по существу ничем он IIFE и не отличаются, и раньше именно с помощью IIFE и эмулировались.

Исходная версия javascript, :

В той же статье на mdn, водном из примеров демонстриуется, как создаются замыкания на скоуп IIFE

The shared lexical environment is created in the body of an anonymous function, which is executed as soon as it has been defined (also known as an IIFE). The lexical environment contains two private items: a variable called privateCounter, and a function called changeBy. You can’t access either of these private members from outside the anonymous function. Instead, you can access them using the three public functions that are returned from the anonymous wrapper.

Those three public functions are closures that share the same lexical environment. Thanks to JavaScript’s lexical scoping, they each have access to the privateCounter variable and the changeBy function.

Посему, если ты хочешь избаваиться от противоречий, то просто воспринимай module\block scope как частный случай IIFE. Они по существу ничем он IIFE и не отличаются, и раньше именно с помощью IIFE и эмулировались.