This commit is contained in:
Jeremy Ashkenas
2011-10-24 13:19:15 -04:00
parent b4d9503340
commit 3c54f79113
2 changed files with 5 additions and 0 deletions

View File

@@ -66,6 +66,10 @@ $(document).ready(function() {
clone.lucky.push(101);
equals(_.last(moe.lucky), 101, 'changes to deep attributes are shared with the original');
equals(_.clone(undefined), void 0, 'non objects should not be changed by clone');
equals(_.clone(1), 1, 'non objects should not be changed by clone');
equals(_.clone(null), null, 'non objects should not be changed by clone');
});
test("objects: isEqual", function() {

View File

@@ -645,6 +645,7 @@
// Create a (shallow-cloned) duplicate of an object.
_.clone = function(obj) {
if (!_.isObject(obj)) return obj;
return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
};