标签:aaa compare cccccc log code style logs span val
根据对象的年龄排序。
var boy = [{ name: "jiang", age: 22 }, { name: "AAAAAAAAAAAAAA", age: 21 }, { name: "CCCCCCCCc", age: 25 }]; function compare(propertyName) { return function(object1, object2) { var value1 = object1[propertyName]; var value2 = object2[propertyName]; if (value2 < value1) { return 1; } else if (value2 > value1) { return -1; } else { return 0; } } }
boy.sort(compare("age"));
标签:aaa compare cccccc log code style logs span val
原文地址:http://www.cnblogs.com/liaozhenting/p/6935686.html