In writing bigger plugins it's often necessary to use clones inside of closures. JavaScript does everything by reference. but sometimes we need to create a clone. While the returned object have this capability: $().clone(); we can't use that in our plugins if what he need to clone a variable without trying to wade through the various ways to do this.
var frink = $.clone(frank);
code:
$.clone = function(obj) {
if(obj == null
typeof(obj) != 'object')
return obj;
var r = obj.split? [] : {};
for(var x in obj)
r[x] = clone(obj[x]);
return r;
}
Attachments
Change History
Download in other formats:
|