Gamby: MinusFour yeah most likely :-/
Wedderburn: But I’ve one more question, since arguments object is not an array and thus shouldn’t have array methods on it, then why does this work just fine Array.prototype.slice.callarguments, 1; why is that slice works for arguments object?
Schimming: RonRichie: slice works on anything that is indexed from 0 and has a ‘length’ property
Wakley: RonRichie: object 1, 2
Schimming: You can see it’s behavior
Wakley: RonRichie: object undefined, 1
Kilbert: Aha, let me digest this lol
Schimming: Array methods all work like that mostly
Schimming: That’s why you can call them on strings too
Schimming: Arguments.slice = .slice;
Dudzic: Got it, thanks a lot :
Schimming: The reason is because arguments inherits from Object.prototype
Mattera: IOW it does not inherit from Array.prototype, which contains .slice and friends
Straight: Do Array.prototype.slice.callarguments
Straight: If you mutate the arguments object it makes things super slow.
Griesbach: Well, most things with arguments will make things super slow
Asquith: Or our new friend Array.from
Straight: Sure, Array.from is great
Eaby: Even p***ing things to Array.prototype.slice.call will make things slow. or at least that’s what i’ve heard. i don’t really use varargs where it would matter.
Wakley: Havvy: The latest version of JavaScript, published in June 2015. For ES6 features see http://www.ecma-international.org/ecma-262/6.0/index.html. To experiment with ES6 now see http://babeljs.io/repl. For availability in browsers see http://kangax.github.io/compat-table/es6/
Straight: Tcsc: not with p***ing arguments to slice
Kallus: Hm. i guess my information was wrong about that.
Schimming: Is the arguments object optimized like an array? or is it treated like a hashtable internally
Straight: Schimming: neither, it’s something else
Rickerson: Schimming: it’s an array-like object. what do you mean by optimized?
Schimming: I’m pretty sure arrays are implemented differently than your standard object
Schimming: But that’s just a hunch really
Pasquale: Sure, and you can bet that argument access/parameter handling is optimized as well : is there some particular performance implications you’re worried about w/ arguments object? hopefully you’re not abusing it too much :
Schimming: Noo we just got on the arguments topic in the channel
Schimming: I only really use arguments when I defer work to other functions
Trucchi: I don’t think it’s the actual use of the arguments object that makes it super slow though the initial access might, it’s just that using .call and .apply is, itself, not very fast
Purkiss: I imagine apply can’t be easily optimized
Trucchi: Yeah, it’s gotta shoehorn the array into the args list, which can get pretty slow as the number of args grow
Schuermann: Right, and it must do this at runtime
Trucchi: That’s why in a lot of cases, it’s better to an accept an array arg than any number of args
Mathson: For a simple variadic function, sure, but it’s a bit more nuanced than that
Dunwiddie: Re: expressiveness tradeoffs
Wecker: But yea you’ll save a bunch on param binding
Trucchi: Also there are plenty of higher-order functions where you don’t know how many arguments there might be, because you don’t know what the callback is gonna be
Kualii: Unless you make all functions monadic and auto-currying!
Trucchi: But I imagine once you’ve accepted that you’re gonna have to do .apply on a function, it doesn’t matter whether you’re calling apply on an array or on the arguments object
Badger: I think you can also optimize it to a switch