documentcloud/underscore — pull request #595 by cederberg (2012-05-07 05:28:16+00:00)
Title: Deep copying with _.clone(obj, deep)

I sometimes return copies of nested internal data structures, so deep copying is needed to avoid accidental changes by other parts of the program or by loaded plug-ins. See also issue #586 and elsewhere.

Since the _.clone() function didn't support deep copies, I thought it would be fairly straight-forward to add it without breaking the API. Not sure that the implementation is the best though.

Also fixed a few corner cases with Date, Function and RegExp objects being cloned. Not very common scenarios perhaps, but easy enough to handle.

### clone_.clone(object, [deep])

Create a copy of the object. The copy is shallow, unless deep is true. This means that nested objects or arrays are copied by reference, not duplicated. Note that the prototype chain is not preserved by this function, unlike Object.create.

```javascript
_.clone({name : 'moe'});
=> {name : 'moe'};

_.clone([1, 2, 3]);
=> [1, 2, 3];
```