本文介绍了使用jquery $ .extend()时忽略属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种有效的方法来克隆对象但是遗漏了指定的属性?理想情况下不重写$ .extend函数?

Is there an efficient way to clone an object yet leave out specified properties? Ideally without rewriting the $.extend function?

var object = {
  "foo": "bar"
  , "bim": Array [1000]
};

// extend the object except for the bim property
var clone = $.extend({}, object, "bim");
// = { "foo":"bar" }

我的目标是保存不要复制我不会使用的东西。

My goal is to save resources by not copying something I'm not going to use.

推荐答案

需要无数个参数,因此无法重写它以适合您请求的格式,打破功能。

jQuery.extend takes an infinite number of arguments, so it's not possible to rewrite it to fit your requested format, without breaking functionality.

但是,您可以使用运营商:

You can, however, easily remove the property after extending, using the delete operator:

var object = {
    "foo": "bar"
  , "bim": "baz"
};

// extend the object except for the bim property
var clone = $.extend({}, object);
delete clone.bim;
// = { "foo":"bar" }

这篇关于使用jquery $ .extend()时忽略属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 05:10