Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 02bada1

Browse files
refact(ngSwitch): don't create extra function in for loop
Closes angular#8927
1 parent 712299c commit 02bada1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/ng/directive/ngSwitch.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ var ngSwitchDirective = ['$animate', function($animate) {
144144
previousLeaveAnimations = [],
145145
selectedScopes = [];
146146

147+
var spliceFactory = function(array, index) {
148+
return function() { array.splice(index, 1); };
149+
};
150+
147151
scope.$watch(watchExpr, function ngSwitchWatchAction(value) {
148152
var i, ii;
149153
for (i = 0, ii = previousLeaveAnimations.length; i < ii; ++i) {
@@ -155,11 +159,7 @@ var ngSwitchDirective = ['$animate', function($animate) {
155159
var selected = getBlockNodes(selectedElements[i].clone);
156160
selectedScopes[i].$destroy();
157161
var promise = previousLeaveAnimations[i] = $animate.leave(selected);
158-
promise.then((function(i) {
159-
return function(){
160-
previousLeaveAnimations.splice(i, 1);
161-
};
162-
}(i)));
162+
promise.then(spliceFactory(previousLeaveAnimations, i));
163163
}
164164

165165
selectedElements.length = 0;

0 commit comments

Comments
 (0)