From a92f6af5807669013aa40771690e0472d7f5da9d Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Mon, 10 Jun 2013 16:40:34 +0800 Subject: Code refactoring --- js/utility.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'js/utility.js') diff --git a/js/utility.js b/js/utility.js index a59841f..fe1d0f1 100644 --- a/js/utility.js +++ b/js/utility.js @@ -5,10 +5,28 @@ * @param {Number} max * @return {Number} */ -Math.rangeInt = function(min, max){ - if (max == undefined) { - max = min; - min = 0; - } - return Math.floor(Math.random() * (max - min + 1)) + min; +if (typeof Math.rangeInt != 'function') { + Math.rangeInt = function(min, max){ + if (max == undefined) { + max = min; + min = 0; + } + return Math.floor(Math.random() * (max - min + 1)) + min; + } +} + +/** + * Mege two objects + * + * @param {Object} o1 Object 1 + * @param {Object} o2 Object 2 + * @return {Object} + */ +if (typeof Object.merge != 'function') { + Object.merge = function(o1, o2) { + for (var i in o1) { + o2[i] = o1[i]; + } + return o2; + } } -- cgit v1.2.3