function createComparisonFunction(propertyName){ return function(obj1,obj2){ var value1 = obj1[propertyName]; var value2 = obj2[propertyName]; if (value1 < value2 ){ return -1; }else if ( value1 > value2 ){ return 1; }else{ return 0; } } } var data = [{name:"zhangsan",age:28},{name:"lisi",age:29}]; data.sort(createComparisonFunction("age")); alert(data[0].name);