How would I create a function that accepts a value and creates a watchfile listener based on that value received?
Example of what I’m trying to do:
function createListener(id) {
var listener(id here) = fs.watchFile(file, function () {
});
});
How could I place the id given to function createListener(); into the listener’s assigned variable?
Example: createListener('5'); would create var listener5 = fs.watchFile();
createListener('23'); would create var listener23 = fs.watchFile();
You can use
evalto create dynamic variable namesbut it is bad part of JavaScript and I strongly recommend not to use
evalat all.I recommend you to use either array or JSON objects to store multiple functions.
Array
JSON