Comment

Comment by dgb23

> Arrow functions are a popular feature in modern JavaScript - they allow us to write functional code in a concise way.

> Rust has something similar and they are called “Closures”. The name might be a bit confusing (...)

This is in turn confusing to me!

I can't imagine a world where you know JS and especially "functional" JS, but haven't heard of the term "closure".

"Arrow functions" are just sugar. They don't have any special meaning. All functions in JS, regardless of whether they are declared, assigned, returned etc., are closures and capture their environment.

Similarly a normally declared function in Rust are first class values as well and for example can be passed into higher order functions.

Giving the benefit of the doubt, I assume that the author knows this and just wanted to introduce the term in a beginner friendly manner. But I think it would be less confusing to just use the term and link to an official documentation:

Rust: https://doc.rust-lang.org/book/ch13-01-closures.html

JS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Clos...

parent dgb23 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton