My application is a local server that receive about 2/3 requests per seconds.
At each request, it stores and update data, process some calculation, update view (react), ...
I would like to know what is faster, when i have to use closures :
Simply create the function where I need it:
var parentValue = 'ok';randomAsyncFunction(function() { console.log(parentValue); }Create a "global" function and then bind the callback with needed values:
function testCallback(value) { console.log(value); }var parentValue = 'ok'; randomAsyncFunction(testCallback.bind(undefined, parentValue));
Note: theses pseudo-codes will be executed 2/3 times per seconds. For the second example, the testCallback function will be created once, and the bind will be called instead of re-creating the function.
So, is it better or worse to use the second example ?