类型错误:无效的 Array.prototype.sort 参数
当 Array.prototype.sort()(及其相关方法)的参数出现以下情况时,会发生 JavaScript 异常 "无效的 Array.prototype.sort 参数":Array.prototype.toSorted()、TypedArray.prototype.sort()、TypedArray.prototype.toSorted()) 既不是 undefined,也不是比较其操作数的函数。
¥The JavaScript exception "invalid Array.prototype.sort argument" occurs when the argument of Array.prototype.sort() (and its related methods: Array.prototype.toSorted(), TypedArray.prototype.sort(), TypedArray.prototype.toSorted()) isn't either undefined or a function which compares its operands.
信息
¥Message
TypeError: The comparison function must be either a function or undefined (V8-based) TypeError: invalid Array.prototype.sort argument (Firefox) TypeError: non-function passed to Array.prototype.toSorted (Firefox) TypeError: invalid %TypedArray%.prototype.sort argument (Firefox) TypeError: Array.prototype.sort requires the comparator argument to be a function or undefined (Safari) TypeError: Array.prototype.toSorted requires the comparator argument to be a function or undefined (Safari) TypeError: TypedArray.prototype.sort requires the comparator argument to be a function or undefined (Safari) TypeError: TypedArray.prototype.toSorted requires the comparator argument to be a function or undefined (Safari)
错误类型
什么地方出了错?
¥What went wrong?
Array.prototype.sort() 的参数(及其相关方法:Array.prototype.toSorted()、TypedArray.prototype.sort()、TypedArray.prototype.toSorted()) 应为 undefined 或比较其操作数的函数。
¥The argument of Array.prototype.sort() (and its related methods: Array.prototype.toSorted(), TypedArray.prototype.sort(), TypedArray.prototype.toSorted()) is expected to be either undefined or a function which compares its operands.