util.clone() no longer falsely attempts to clone functions
parent
4a0537223b
commit
604e03fa55
|
@ -146,6 +146,12 @@ exports.clone = function clone( data, deep )
|
|||
|
||||
return ret;
|
||||
}
|
||||
else if ( typeof data === 'function' )
|
||||
{
|
||||
// It is pointless to clone a function. Even if we did clone those that
|
||||
// support toSource(), they'd still do the same damn thing.
|
||||
return data;
|
||||
}
|
||||
else if ( data instanceof Object )
|
||||
{
|
||||
var newobj = {},
|
||||
|
|
|
@ -103,3 +103,20 @@ for ( prop in deep_obj )
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* "Cloning" functions doesn't necessarily make sense. It can, depending on how
|
||||
* you think about it. We can do a toSource() in many circumstances and create a
|
||||
* new function from that. But what's the point? It still does the same thing.
|
||||
* As such, functions will not be cloned. They'll be returned by reference.
|
||||
*/
|
||||
( function testCloneDoesNothingWithFunctions()
|
||||
{
|
||||
var func = function() {},
|
||||
obj = { foo: func };
|
||||
|
||||
assert.ok( func === util.clone( obj, true ).foo,
|
||||
"Functions should not be cloned"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
|
Loading…
Reference in New Issue