0

我想验证一个对象,也许这个对象可以有额外的参数,但我只想要一些。克隆的最佳方法是什么。我尝试了下划线,但没有任何反应:

var object = {
      name: "Pepe",
      age: 25,
      widget: {
         top: 1,
         left: 1,
         other: "jeje"
      }
};
var a = _.pick(object, "name", "widget.top");
console.log(a);
//Will must return: {name: "pepe", widget: {top: 1}}
4

1 回答 1

0
var object = {
      name: "Pepe",
      age: 25,
      widget: {
         top: 1,
         left: 1,
         other: "jeje"
      }
};

var a = _.pick(object,'name','widget');
a.widget = _.pick(a.widget,'top');
于 2013-08-22T18:31:16.457 回答