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

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

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.

Thanks!

here’s the screenshot.

#2

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
#3

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:

#4

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.

#5

So my stopEventBubbling function, is a HOF?

#6

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