From 2021c859890a9c9b12337fce616a60e61fbf61cf Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 16 Dec 2014 10:10:37 -0500 Subject: [PATCH] feature(util) rm slice --- lib/client.js | 2 +- lib/client/buffer.js | 5 ++--- lib/client/dom.js | 2 +- lib/client/polyfill.js | 4 ++-- lib/client/view.js | 14 +++++++------- lib/server/rest.js | 4 ++-- lib/util.js | 22 ++++------------------ test/lib/cloudfunc.js | 2 +- test/lib/util.js | 28 +--------------------------- 9 files changed, 21 insertions(+), 62 deletions(-) diff --git a/lib/client.js b/lib/client.js index 70997175..6b51bcec 100644 --- a/lib/client.js +++ b/lib/client.js @@ -165,7 +165,7 @@ var Util, DOM, CloudFunc, join; if (path) { module = query[0]; - module = Util.slice(module, 1).join(''); + module = module.slice(1).join(''); module = getStrBigFirst(module); file = query[1]; diff --git a/lib/client/buffer.js b/lib/client/buffer.js index c27addbb..7081fb74 100644 --- a/lib/client/buffer.js +++ b/lib/client/buffer.js @@ -42,10 +42,9 @@ var Util, DOM; } function rmCutClass() { - var files = DOM.getByClassAll(CLASS), - array = Util.slice(files); + var files = DOM.getByClassAll(CLASS); - array.forEach(function(element) { + [].forEach.call(files, function(element) { DOM.removeClass(element, CLASS); }); } diff --git a/lib/client/dom.js b/lib/client/dom.js index 65c2226b..b927a9c0 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -734,7 +734,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; this.getSelectedFiles = function() { var panel = DOM.getPanel(), selected = this.getByClassAll(SELECTED_FILE, panel), - ret = Util.slice(selected); + ret = [].slice.call(selected); return ret; }; diff --git a/lib/client/polyfill.js b/lib/client/polyfill.js index a66eb22e..1d2b7859 100644 --- a/lib/client/polyfill.js +++ b/lib/client/polyfill.js @@ -33,11 +33,11 @@ var Util, DOM, jQuery; if (!Function.bind) Function.prototype.bind = function (context) { - var aArgs = Util.slice(arguments, 1), + var aArgs = [].slice.call(arguments, 1), fToBind = this, NOP = function () {}, fBound = function () { - var arr = Util.slice(arguments), + var arr = [].slice.call(arguments), args = aArgs.concat(arr); return fToBind.apply(context, args); diff --git a/lib/client/view.js b/lib/client/view.js index 659650b0..978d5bd0 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -292,19 +292,19 @@ var CloudCmd, Util, DOM, CloudFunc, $; function onOverLayClick(overlay, event) { var isCurrent, isFiles, isFilesPassive, - files = Util.slice(Info.files), - filesPassive= Util.slice(Info.filesPassive), - position = CloudCmd.MousePosition, - element = event.target, - isOverlay = element === overlay; + files = Info.files, + filesPassive = Info.filesPassive, + position = CloudCmd.MousePosition, + element = event.target, + isOverlay = element === overlay; if (isOverlay) { hideOverlay(); element = DOM.getCurrentByPosition(position); if (element) { - isFiles = ~files.indexOf(element); - isFilesPassive = ~filesPassive.indexOf(element); + isFiles = ~[].indexOf.call(files, element); + isFilesPassive = ~[].indexOf.call(filesPassive, element); if (isFiles || isFilesPassive) { isCurrent = DOM.isCurrentFile(element); diff --git a/lib/server/rest.js b/lib/server/rest.js index bb2ff809..a2f322f0 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -198,7 +198,7 @@ files.to = mellow.convertPath(files.to); if (files.names) - data = Util.slice(files.names); + data = files.names.slice(); else data = files; @@ -226,7 +226,7 @@ files.from = mellow.convertPath(files.from); files.to = mellow.convertPath(files.to); - data = Util.slice(files.names); + data = files.names.slice(); copyFiles(files, flop.copy, function(error) { var msg = formatMsg('copy', data); diff --git a/lib/util.js b/lib/util.js index 6813cffb..b2725952 100644 --- a/lib/util.js +++ b/lib/util.js @@ -252,7 +252,7 @@ * @param pArg */ this.log = function() { - var args = this.slice(arguments), + var args = [].slice.call(arguments), console = Scope.console, lDate = '[' + Util.getDate() + '] '; @@ -430,20 +430,6 @@ return type; } - /** - * function makes new array based on first - * - * @param array - */ - this.slice = function(array, begin, end) { - var ret = []; - - if (array) - ret = [].slice.call(array, begin, end); - - return ret; - }; - this.exec = new ExecProto(); function ExecProto() { @@ -457,7 +443,7 @@ var exec = function(callback) { var ret, isFunc = Util.type.function(callback), - args = Util.slice(arguments, 1); + args = [].slice.call(arguments, 1); if (isFunc) ret = callback.apply(null, args); @@ -485,7 +471,7 @@ */ exec.ret = function() { var result, - args = Util.slice(arguments); + args = [].slice.call(arguments); args.unshift(exec); result = exec.with.apply(null, args); @@ -564,7 +550,7 @@ } function checkFunc(num, data, all) { - var args = Util.slice(data, 1), + var args = [].slice.call(data, 1), isLast = false, error = data[0], length = args.length; diff --git a/test/lib/cloudfunc.js b/test/lib/cloudfunc.js index b42f75bb..9bef0296 100644 --- a/test/lib/cloudfunc.js +++ b/test/lib/cloudfunc.js @@ -87,7 +87,7 @@ Expect += expect; - isNotOk = Util.slice(Expect).some(function(item, number) { + isNotOk = Expect.split('').some(function(item, number) { var ret = result[number] !== item; if (ret) diff --git a/test/lib/util.js b/test/lib/util.js index 650adba8..8b1a6472 100644 --- a/test/lib/util.js +++ b/test/lib/util.js @@ -83,7 +83,7 @@ it('should return function that try to call callback', function() { var STR = 'hello world', func1 = function() { - var args = Util.slice(arguments); + var args = [].slice.call(arguments); return args.join(' '); }, @@ -127,32 +127,6 @@ }); }); - - describe('slice', function() { - it('should return copy of given array', function() { - var arr1 = [1, 2, 3], - length = arr1.length, - arr2 = Util.slice(arr1); - - arr2.should.be.instanceof(Array) - .and.have.lengthOf(length); - }); - - it('should return empty array on given undefined', function() { - var arr = Util.slice(), - LENGTH = 0; - - arr.should.be.instanceof(Array) - .and.have.lengthOf(LENGTH); - }); - - it('should return sliced array', function() { - var arr = Util.slice([1,2,3], 1); - - arr.should.eql([2, 3]); - }); - - }); }); })();