Return a copy of the object, filtered to only have values for the whitelisted keys (or array of valid keys).

返回一个对象的副本,筛选过滤,只有白名单键的值

1 _.pick({name : 'moe', age: 50, userid : 'moe1'}, 'name', 'age');
2 => {name : 'moe', age : 50}

源码:

  _.pick = function(obj) {
    var result = {};
    each(_.flatten(slice.call(arguments, 1)), function(key) {
      if (key in obj) result[key] = obj[key];
    });
    return result;
  }
posted on 2012-04-16 21:54  himanhimao  阅读(382)  评论(0编辑  收藏  举报