I am trying to create a function that duplicates an array of arrays. I tried blah.slice (0); but it only copies links. I need to make a duplicate that will leave the original intact.
I found this prototype method http://my.opera.com/GreyWyvern/blog/show.dml/1725165
Object.prototype.clone = function() {
var newObj = (this instanceof Array) ? [] : {};
for (i in this) {
if (i == 'clone') continue;
if (this[i] && typeof this[i] == "object") {
newObj[i] = this[i].clone();
} else newObj[i] = this[i]
} return newObj;
};
This works, but it confuses the jQuery plugin that I use, so I need to turn it into a function ... and recursion is not the strongest.
Your help will be appreciated!
Greetings
source
share