I would like to curry a function with different values from an object and save the created functions as object keys. The curried value gets overwritten while looping
function print (a,b){
console.log(a + b)
}
var functions = {
foo : "",
bar : ""
}
for (var key in functions) {
functions[key] = function(a){
var val = key; // the problematic part saving the value
return print(a,val)
}
}
functions.foo('test-')
functions.bar('test-')
output
>>>test-bar
>>>test-bar
desired output
>>>test-foo
>>>test-bar
im missing the idea on how to save the val variable for good and not overwriting it while looping