主题
clone
js
_.clone(value)
创建 value
的浅克隆。
¥Creates a shallow clone of value
.
注意:此方法大致基于 结构化克隆算法,支持克隆数组、数组缓冲区、布尔值、日期对象、映射、数字、Object
对象、正则表达式、集合、字符串、符号和类型化数组。arguments
对象的自身可枚举属性被克隆为普通对象。对于不可克隆的值(例如错误对象、函数、DOM 节点和 WeakMap),将返回一个空对象。
¥Note: This method is loosely based on the structured clone algorithm and supports cloning arrays, array buffers, booleans, date objects, maps, numbers, Object
objects, regexes, sets, strings, symbols, and typed arrays. The own enumerable properties of arguments
objects are cloned as plain objects. An empty object is returned for uncloneable values such as error objects, functions, DOM nodes, and WeakMaps.
新增于
¥Since
0.1.0
参数
¥Arguments
value
(*):要克隆的值。¥
value
()*: The value to clone.
返回
¥Returns
(*):返回克隆的值。
¥()*: Returns the cloned value.
示例
¥Example
js
var objects = [{ 'a': 1 }, { 'b': 2 }];
var shallow = _.clone(objects);
console.log(shallow[0] === objects[0]);
// => true