But there is another option. We can pass an anonymous callback to our handler. This way, our handler itself will serve as a pointer, and we will not have to give an anonymous function to our onClick event. The name of this design pattern is called currying.
This is very confused - you are still passing an anonymous function to the onClick event - albeit one created by a higher order function - there are no 'pointers' involved. Also, you haven't curried anything here. Currying is the act of transforming a function that takes multiple arguments into a series of functions that each take 1 argument.
The function you have named myHandler isn't a handler at all - it is a function that creates a handler. It would be better named createHandler.
An example of currying a function:
// 'normal' function stylefunctionadd(a,b){returna+b}functionaddCurried(a){returnfunction(b){returna+b}}// or 'arrow' function styleconstadd=(a,b)=>a+bconstaddCurried=a=>b=>a+b// usageadd(1,2)// 3addCurried(1)(2)// 3addCurried(7)// functionconstadd5=addCurried(5)add5(3)// 8
This is very confused - you are still passing an anonymous function to the
onClick
event - albeit one created by a higher order function - there are no 'pointers' involved. Also, you haven't curried anything here. Currying is the act of transforming a function that takes multiple arguments into a series of functions that each take 1 argument.The function you have named
myHandler
isn't a handler at all - it is a function that creates a handler. It would be better namedcreateHandler
.An example of currying a function:
Thank you! I was reading through this and thinking... this isn't currying at all.