From 2a6999336f57b71975b6fd55460820c9f09f160c Mon Sep 17 00:00:00 2001 From: David Sheiles Date: Fri, 25 Nov 2016 15:25:17 +1100 Subject: [PATCH] Update to make compatible with jQuery This update fixes issues where the file would cause jQuery to break. This is in response to https://github.com/daleharvey/pacman/issues/8 For more info on the reason why it causes an issue - http://stackoverflow.com/questions/14941657/why-does-this-javascript-prototype-function-break-jquery --- pacman.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pacman.js b/pacman.js index fd0dfd6..0bfb2f7 100644 --- a/pacman.js +++ b/pacman.js @@ -587,7 +587,7 @@ Pacman.Map = function (size) { } function reset() { - map = Pacman.MAP.clone(); + map = cloneObj(Pacman.MAP); height = map.length; width = map[0].length; }; @@ -1253,17 +1253,18 @@ Pacman.WALLS = [ {"line": [10.5, 9.5]}] ]; -Object.prototype.clone = function () { - var i, newObj = (this instanceof Array) ? [] : {}; - for (i in this) { +function cloneObj(obj) { + var i, newObj = (obj instanceof Array) ? [] : {}; + for (var 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] = cloneObj(obj[i]); } else { - newObj[i] = this[i]; + newObj[i] = obj[i]; } } return newObj; }; +