Javascript排序回调

gyo*_*sko 3 javascript sorting

我需要排序一个大的Javascript项目列表,我正在使用这样的sort函数:

var sorted_list = non_sorted.sort(function(a,b){
// Sort stuff here
});
Run Code Online (Sandbox Code Playgroud)

我想做的是在sort函数完成时调用函数.

是否可以添加回调函数来排序或在事件结束时触发事件sort

Guf*_*ffa 13

你太复杂了.该sort方法不是异步的,因此您不需要回调或事件.只需将代码放在调用的代码之后sort:

var sorted_list = non_sorted.sort(function(a,b){
  // comparer
});
// The code just continues here after the sort
Run Code Online (Sandbox Code Playgroud)