[removed] sort objects

后端 未结 4 717
温柔的废话
温柔的废话 2021-01-13 22:46
function Player() {
  var score;

  this.getScore = function() { return score; }
  this.setScore = function(sc) { score = sc; }
}

function compare(playerA, playerB)         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 23:13

    you can also use like below:

    var a = [];
    a.push(obj1);
    a.push(obj2);
    a.sort(compare);
    

    so you can use push method rather than an integer index

提交回复
热议问题