mardi 1 août 2017

Design pattern ? passing same multiple argument to the functions and function inside

I need to make some kind of form item factory with javascript. The idea is that you get the data from backend and produce the forms which need to have different event handler which is taking same argument but different contents.

const updateHandler = (dispatch, formName, section) => {

   return (value) => {
     //do some stuff with value
     //... this part is different for the each different form


     //call function that handles updating redux and url
     function(dispatch, formName, section, value, ...)
     //taking same argument
   }

}

I am wondering if I can memorize 3 shared argument for sub function so that i do not have to pass same thing again. I thought about currying or apply but i do not i can achieve that with currying or apply.

Aucun commentaire:

Enregistrer un commentaire