1. var array = [
    2. {name: 'a', phone: 1},
    3. {name: 'b', phone: 5},
    4. {name: 'd', phone: 3},
    5. {name: 'c', phone: 4}
    6. ]
    7. array.sort(getSortFun('desc', 'phone'));
    8. function getSortFun(order, sortBy) {
    9. var ordAlpah = (order == 'asc') ? '>' : '<';
    10. var sortFun = new Function('a', 'b', 'return a.' + sortBy + ordAlpah + 'b.' + sortBy + '?1:-1');
    11. return sortFun;
    12. }
    13. console.log(array);