2 ms·
I have only just started learning the details of JavaScript. While reading JavaScript: The Good Parts I found myself asking the question what the difference bet
by heidar 13y ago
I have only just started learning the details of JavaScript. While reading JavaScript: The Good Parts I found myself asking the question what the difference between a module and a closure is. As far as I can tell they are the same thing. Is that correct or am I missing something?
- natefaubion 13y agoThere aren't native modules in JS (though they are coming in ES6). The module pattern is a way of having private scope by wrapping everything in a closure. So yes, the module pattern just creates a closure and returns an object (or assigns to global scope) with its public members.
- bti 13y agoA module is a design pattern and a closure is a language construct. A module (in the context of the "module pattern") is a closure but all closures are not "modules".