Brendan Eich (2012-12-30T22:47:14.000Z)
github at esdiscuss.org (2013-07-12T02:26:06.466Z)
Domenic Denicola wrote: > From: Anne van Kesteren > >> On Sun, Dec 30, 2012 at 10:22 PM, Axel Rauschmayer <axel at rauschma.de> wrote: >>> 5. Array-like objects [not completely fixed (DOM...), but `arguments` >> We've made some effort towards changing some of this, but legacy content is against us. :/ > > I saw this happen, and was sad, but never understood what the legacy problem was. > > Similarly, when people ask me "why can't they just make arguments a real array" (perhaps with magic aliasing behavior in sloppy mode), I don't know the answer. > > So just out of curiosity, how does legacy code break when making array-likes into real arrays? I feel like the Liskov Substitution Principle should have our back here. LSP is not magic. Works better when you have a type system. The history of what went wrong is recorded here: https://mail.mozilla.org/pipermail/es5-discuss/2009-August/003112.html Read the followups. I'll cite Oliver's message in full below. --- Problem with Arguments inheriting from Array Oliver Hunt oliver at apple.com /Mon Aug 17 16:08:21 PDT 2009/ I implement the logic to make the Arguments object inherit from Array in WebKit last friday and it's quickly turned up a severe incompatibility with Prototype.js, specifcally Prototype's isArray function: ```js isArray: function(object) { return object != null && typeof object == "object" && 'splice' in object && 'join' in object; } ``` This breaks at the very least a number of Apple sites and Nasa.gov -- that's just two of the top row of sites onhttp://www.prototypejs.org/real-world , other sites didn't appear to be broken but then i was merely looking at loading the front page, nothing more. Unfortunately the use of 'in' means we also can't just shadow a less useful function with null or undefined for now. Due to these site breakages, caused by a major compatibility problem in a fairly major library it seems infeasible to attempt to retrofit array like behaviour onto arguments. --Oliver