DEV Community

Discussion on: Arrow Function vs Function

Collapse
terpinmd profile image
terpinmd

Hmm. I think there are some issues with this write-up. Not sure why you are calling function() closures. Both "function" and fat arrow are functions, and they both can be closures, with the difference being their lexical scope.

A closure is just a function that has access to variables in its scope. Its really more of a pattern/feature.

Also I don't know that "function" is more or less OOP than fat arrow.

I think you should consider editing this article, at minimum the terminology is not correct for what you are calling a closure

Collapse
sshymko profile image
Sergii Shymko Author • Edited

Thanks for a very detailed constructive feedback! Much appreciated!

Indeed, coming from PHP, I've used the term "closure" synonymously to "anonymous function" that can optionally reference the outer scope (becoming a closure). Agreed, it's unacceptable in JavaScript and strictly speaking incorrect. Updated the article accordingly.

The OOP remark referred to inability to use arrow functions as class constructors. See the code example in the comment below. Will try to rephrase or expand on this topic to avoid confusion.

P.S.

the best way to get the right answer on the internet is not to ask a question; it's to post the wrong answer.

Cunningham's Law

Thanks!