Is there a way to do something like this?
//in file 1
function foo(val1, callback){
callback(bar(val1)); //this will through an error
//callback(bar); is the proper way, but then I'm not passing val1 (and I need to be able to set val2 inside the file 2 callback)
}
function bar(val1, val2){
console.log(val1, val2);
}
//in file 2
foo('value1', function(bar){
bar('value2');
});
and have that log: value1 value2
?
I know I could just pass val1
into the callback, and then pass it again as bar(val1, 'value2')
, but I'm wondering if there is a way to automate passing val1
instead of passing it manually. The file 2 function foo
is going to be run a lot, and it would be nice to not have to pass the same parameter every time I want to run bar()