Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit e15d2fd

Browse files
refact($anchorScroll): use Array.some for better performance
1 parent daf3737 commit e15d2fd

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/ng/anchorScroll.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@ function $AnchorScrollProvider() {
6262
this.$get = ['$window', '$location', '$rootScope', function($window, $location, $rootScope) {
6363
var document = $window.document;
6464

65-
// helper function to get first anchor from a NodeList
66-
// can't use filter.filter, as it accepts only instances of Array
67-
// and IE can't convert NodeList to an array using [].slice
68-
// TODO(vojta): use filter if we change it to accept lists as well
65+
// Helper function to get first anchor from a NodeList
66+
// (using `Array#some()` instead of `angular#forEach()` since it's more performant
67+
// and working in all supported browsers.)
6968
function getFirstAnchor(list) {
7069
var result = null;
71-
forEach(list, function(element) {
72-
if (!result && nodeName_(element) === 'a') result = element;
70+
Array.prototype.some.call(list, function(element) {
71+
if (nodeName_(element) === 'a') {
72+
result = element;
73+
return true;
74+
}
7375
});
7476
return result;
7577
}

0 commit comments

Comments
 (0)