We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

TypeError: invalid Array.prototype.sort argument

信息

TypeError: invalid Array.prototype.sort argument (Firefox)

错误类型

TypeError

哪里出错了?

Array.prototype.sort() 的参数预期为 undefined 或者是一个比较操作数的函数。

示例

无效的

[1, 3, 2].sort(5);  // TypeError

var cmp = { asc: (x, y) => x >= y, dsc : (x, y) => x <= y };
[1, 3, 2].sort(cmp[this.key] || 'asc');  // TypeError

有效的

[1, 3, 2].sort();   // [1, 2, 3]


var cmp = { asc: (x, y) => x >= y, dsc : (x, y) => x <= y };
[1, 3, 2].sort(cmp[this.key || 'asc']); // [1, 2, 3]

相关

文档标签和贡献者

此页面的贡献者: hui1993, Ende93
最后编辑者: hui1993,