getify / Functional-Light-JS

Pragmatic, balanced FP in JavaScript. @FLJSBook on twitter.
http://FLJSBook.com
Other
16.64k stars 1.96k forks source link

Ch 2: `arguments` object not deprecated #35

Closed shshaw closed 7 years ago

shshaw commented 7 years ago

In chapter 2, you state As of ES5, arguments is deprecated., but from the information I can find, the arguments object itself is not deprecated, but rather the property Function.arguments is.

MDN's recommendation from Deprecated and Obsolete Features is:

The caller and arguments [Function] properties are deprecated, because they leak the function caller. Instead of the arguments property, you should use the arguments object inside function closures.

If I'm mistaken, do you have any resources showing the deprecation of the arguments object?

getify commented 7 years ago

There's no such thing as formal deprecation in this respect. Informal deprecation means influential developers telling others "stop using it", which has been pretty common in my observation. However, it'll never be actually removed from JS.

The evidence for informal deprecation of arguments includes the fact that its behavior was altered in strict mode (of ES5) to not be bound to its corresponding named arguments, as well as the fact that in ES6 the ... rest operator obviates most common needs for arguments. Moreover, arguments being "array-like" instead of a real array has been the extremely common footgun that trips up devs for so many years, which is why it's so often frowned upon.

shshaw commented 7 years ago

Ah, thanks for explaining.

Perhaps rephrasing that in the chapter would make that clearer:

With the addition of the rest operator (...) in ES5, it's strongly suggested that you avoid using the arguments object whenever possible to avoid many complications that it can introduce.