|
|
|
|
|
by asdf-asdf-asdf
2119 days ago
|
|
nobody thinks that this behavior is good. the problem is, this is how it was at the beginning, and javascript will not break backwards compatibility. so we have to live with it (or use a third-party sort-function, like "lodash.sortBy"). there are other similar problems in javascript too: - "typeof null === 'object'". this is very wrong, but again,this is how it was implemented at the beginning... you know the rest ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... ) - another problem with ".sort()" is that it both mutates the input-array and returns the mutated input-array. so you write code like "const arr2 = arr1.sort()", and the code works, but if you don't know the spec, you will not know that "arr1" was modified and basically "arr1 === arr2". |
|