DEV Community

Discussion on: Introduction: from function to closure

stereobooster profile image
stereobooster Author

Every time you call const df = debounce(f) it will create new closure, which contains inside of it anonymous function (return x => {) which will be returned (and assigned to df in this case). But after this you use df which is one instance of the function. If you call const df2 = debounce(f) it will create another closure and another anonymous function.

It works the same way as if you would assign variable. Consider following code example const test = () => [] it will create new instance of array every time you call it (test() !== test()).

Did I answer your question?

dhkamp profile image
David Hölkeskamp

Definately thank you - just thought there would be some kind of optimization going on inside the engine like memoization.