Array.prototype.sort( callbackfn [ , thisArg ] )
# Jordan Harband (5 years ago)
I'd assume it's because sort predates ES5, when the thisArg was added; and
also because a well-behaved comparator only operates based on a
and b
-
why would you need a receiver?
# Jordan Harband (5 years ago)
What's the issue with creating a new function for that case, that accesses the other list in its closure?
(Arrow functions, or .bind, are cheap; the thisArg
makes it basically
impossible to add extra args to all functions that have it, and is almost
never used)
# Michaël Rouges (5 years ago)
About arrow functions/binding, it's just a principle, I try to never create some function on-the-fly, I'm working only by immutable objects derivation.
But, ok, if no choice, I'll do that. ;)
Is there a reason to not have a
thisArg
for theArray.prototype.sort()
callback?Actually, it enforces to bind the context or to have nested functions, each one creating a new function where it isn't strictly necessary.
Michaël Rouges - Lcfvs - @Lcfvs