From 6f63623b935c0c37e2f4143d448db5d2316c574d Mon Sep 17 00:00:00 2001 From: Hyunje Alex Jun Date: Mon, 22 Feb 2016 20:46:28 +0900 Subject: [PATCH] Modify helper.clone to clone an array too --- src/js/lib/helper.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/js/lib/helper.js b/src/js/lib/helper.js index 5a4b25e..ea2d748 100644 --- a/src/js/lib/helper.js +++ b/src/js/lib/helper.js @@ -3,17 +3,19 @@ var cls = require('./class') , d = require('./dom'); -exports.toInt = function (x) { +var toInt = exports.toInt = function (x) { return parseInt(x, 10) || 0; }; -exports.clone = function (obj) { +var clone = exports.clone = function (obj) { if (obj === null) { return null; + } else if (obj.constructor === Array) { + return obj.map(clone); } else if (typeof obj === 'object') { var result = {}; for (var key in obj) { - result[key] = this.clone(obj[key]); + result[key] = clone(obj[key]); } return result; } else { @@ -22,9 +24,9 @@ exports.clone = function (obj) { }; exports.extend = function (original, source) { - var result = this.clone(original); + var result = clone(original); for (var key in source) { - result[key] = this.clone(source[key]); + result[key] = clone(source[key]); } return result; }; @@ -47,11 +49,11 @@ exports.removePsClasses = function (element) { }; exports.outerWidth = function (element) { - return this.toInt(d.css(element, 'width')) + - this.toInt(d.css(element, 'paddingLeft')) + - this.toInt(d.css(element, 'paddingRight')) + - this.toInt(d.css(element, 'borderLeftWidth')) + - this.toInt(d.css(element, 'borderRightWidth')); + return toInt(d.css(element, 'width')) + + toInt(d.css(element, 'paddingLeft')) + + toInt(d.css(element, 'paddingRight')) + + toInt(d.css(element, 'borderLeftWidth')) + + toInt(d.css(element, 'borderRightWidth')); }; exports.startScrolling = function (element, axis) {