diff --git a/pacman.js b/pacman.js index fd0dfd6..6594b08 100644 --- a/pacman.js +++ b/pacman.js @@ -587,7 +587,7 @@ Pacman.Map = function (size) { } function reset() { - map = Pacman.MAP.clone(); + map = clone(Pacman.MAP); height = map.length; width = map[0].length; }; @@ -1253,16 +1253,17 @@ Pacman.WALLS = [ {"line": [10.5, 9.5]}] ]; -Object.prototype.clone = function () { - var i, newObj = (this instanceof Array) ? [] : {}; - for (i in this) { + +function clone(obj) { + var i, newObj = (obj instanceof Array) ? [] : {}; + for (i in obj) { if (i === 'clone') { continue; } - if (this[i] && typeof this[i] === "object") { - newObj[i] = this[i].clone(); + if (obj[i] && typeof obj[i] === "object") { + newObj[i] = clone(obj[i]); } else { - newObj[i] = this[i]; + newObj[i] = obj[i]; } } return newObj;