Test clone method

This commit is contained in:
Maxime Thirouin
2014-05-04 08:33:59 +02:00
parent 25a725c858
commit 7631cc92c7
2 changed files with 29 additions and 0 deletions

12
src/scripts/lib/clone.js Normal file
View File

@@ -0,0 +1,12 @@
module.exports = function(obj) {
if (null === obj || "object" != typeof obj) {
return obj
}
var copy = obj.constructor()
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) {
copy[attr] = obj[attr]
}
}
return copy
}