From 02bada130e5e0aa51bf9a00d9c5421f2bbbd4405 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 4 Sep 2014 13:00:05 +0100 Subject: [PATCH] refact(ngSwitch): don't create extra function in for loop Closes #8927 --- src/ng/directive/ngSwitch.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index 3a7377f0..4c11f62f 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -144,6 +144,10 @@ var ngSwitchDirective = ['$animate', function($animate) { previousLeaveAnimations = [], selectedScopes = []; + var spliceFactory = function(array, index) { + return function() { array.splice(index, 1); }; + }; + scope.$watch(watchExpr, function ngSwitchWatchAction(value) { var i, ii; for (i = 0, ii = previousLeaveAnimations.length; i < ii; ++i) { @@ -155,11 +159,7 @@ var ngSwitchDirective = ['$animate', function($animate) { var selected = getBlockNodes(selectedElements[i].clone); selectedScopes[i].$destroy(); var promise = previousLeaveAnimations[i] = $animate.leave(selected); - promise.then((function(i) { - return function(){ - previousLeaveAnimations.splice(i, 1); - }; - }(i))); + promise.then(spliceFactory(previousLeaveAnimations, i)); } selectedElements.length = 0;