diff options
Diffstat (limited to 'src/common.js')
-rw-r--r-- | src/common.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common.js b/src/common.js new file mode 100644 index 0000000..5606706 --- /dev/null +++ b/src/common.js @@ -0,0 +1,22 @@ +Object.prototype.clone = Array.prototype.clone = function() //https://stackoverflow.com/questions/12690107/clone-object-without-reference-javascript +{ + if (Object.prototype.toString.call(this) === '[object Array]') + { + var clone = []; + for (var i=0; i<this.length; i++) + clone[i] = this[i].clone(); + + return clone; + } + else if (typeof(this)=="object") + { + var clone = {}; + for (var prop in this) + if (this.hasOwnProperty(prop)) + clone[prop] = this[prop].clone(); + + return clone; + } + else + return this; +}
\ No newline at end of file |