定义方法 指定属性值的大小
var compare = function(property) {return function(a,b) {var value1 = a[property];
var value2 = b[property];
return value1 - value2
}
var arr = [
{id: 1},
{id: 3},
{id: 2},
{id: 6},
{id: 5},
{id: 7}
]
arr.sort(this.compare("id"))
该方法会直接改变原数组的排序