Minimal introduction: from theoretical concept of function to practical usage of closures in programming. I show the same concept from different po...
For further actions, you may consider blocking this person and/or reporting abuse
Nice read - I like it.
I've got one question regarding performance and your anonymous function inside your debounce function.
Will the engine (e.g. V8) remember your function internals or will it create the anonymous function, inside it's function storage, everytime debounce gets called?
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 todf
in this case). But after this you usedf
which is one instance of the function. If you callconst 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?
Definately thank you - just thought there would be some kind of optimization going on inside the engine like memoization.
Saving this for the next jr dev I have under me, really nicely illustrated way to explain each step. Thanks!