Look at my code: Is this a closure or a HOF?

Hi campers!

I’m just trying out DOM scripting and i noticed i’m doing a pattern here. I just curious to know if what i did is a Closure or a HOC.


here’s the screenshot.

A Higher Order Component is the conventional name given to a function in React that wraps another component. It allows you to do something to the parameters you pass in before rendering the inner component.

It is a closure. HoC just a name give to a React-specific pattern.

A closure is just a function + it’s local environment - like, you have a function, which does {stuff}, and you also have the little environment that comes with it (eg the local variables inside it). In a language with first-class functions like JS, the computer stores both those things together when you define a function.

1 Like

My mistake, it was supposed to be higher order function. So it isn’t a higher order function.

I agree. Because it’s not returning an enhanced function

Thanks Dan. :slight_smile:

Ah, I see, the question makes a bit more sense! A higher-order function either takes a function as an argument, or returns a function, or both. So addEventListener is a higher-order function.

So my stopEventBubbling function, is a HOF?

Yes, that as well! Functions all the way down.