I thought I knew what closure was, but I'm not so sure that I was reading some article around.
Is the function below "thunk"? (this is a closure for me, I took it from a blog post about the reaction https://spin.atomicobject.com/2016/10/05/form-validation-react/ )
The author explains: "Then we look at the ruleRunner function. RuleRunner is a thunk or function that returns a function.
export const ruleRunner = (field, name, ...validations) => {
return (state) => {
for (let v of validations) {
let errorMessageFunc = v(state[field], state);
if (errorMessageFunc) {
return {[field]: errorMessageFunc(name)};
}
}
return null;
};
};
On the contrary, I thought that thunk is "a function that contains the entire context (state, functions, etc.) that will be needed in order to execute some kind of logic in the future." from: http://www.austinstory.com/what-is-a-thunk-in-javascript/
const add = (x,y) => x + y;
const thunk = () => add(1,2);
thunk()
, thunk. , .
, thunk, , thunk - ", (, ..), - ".