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

Commit 300bffc

Browse files
realitykingpetebacondarwin
authored andcommittedSep 3, 2014
refactor(indexOf) use Array.prototype.indexOf exclusively
Replace helper functions with the native ES5 method Closes #8847
1 parent 5b2a386 commit 300bffc

12 files changed

+12
-36
lines changed
 

‎src/.jshintrc

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"map": false,
5959
"size": false,
6060
"includes": false,
61-
"indexOf": false,
6261
"arrayRemove": false,
6362
"isLeafNode": false,
6463
"copy": false,

‎src/Angular.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
map: true,
5454
size: true,
5555
includes: true,
56-
indexOf: true,
5756
arrayRemove: true,
5857
isLeafNode: true,
5958
copy: true,
@@ -651,20 +650,11 @@ function size(obj, ownPropsOnly) {
651650

652651

653652
function includes(array, obj) {
654-
return indexOf(array, obj) != -1;
655-
}
656-
657-
function indexOf(array, obj) {
658-
if (array.indexOf) return array.indexOf(obj);
659-
660-
for (var i = 0; i < array.length; i++) {
661-
if (obj === array[i]) return i;
662-
}
663-
return -1;
653+
return Array.prototype.indexOf.call(array, obj) != -1;
664654
}
665655

666656
function arrayRemove(array, value) {
667-
var index = indexOf(array, value);
657+
var index = array.indexOf(value);
668658
if (index >=0)
669659
array.splice(index, 1);
670660
return value;
@@ -769,7 +759,7 @@ function copy(source, destination, stackSource, stackDest) {
769759
stackDest = stackDest || [];
770760

771761
if (isObject(source)) {
772-
var index = indexOf(stackSource, source);
762+
var index = stackSource.indexOf(source);
773763
if (index !== -1) return stackDest[index];
774764

775765
stackSource.push(source);

‎src/ng/directive/form.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function FormController(element, attrs, $scope, $animate) {
191191
var pendingChange, pending = form.$pending && form.$pending[validationToken];
192192

193193
if (pending) {
194-
pendingChange = indexOf(pending, control) >= 0;
194+
pendingChange = pending.indexOf(control) >= 0;
195195
if (pendingChange) {
196196
arrayRemove(pending, control);
197197
pendingCount--;

‎src/ng/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ function $HttpProvider() {
10081008

10091009

10101010
function removePendingReq() {
1011-
var idx = indexOf($http.pendingRequests, config);
1011+
var idx = $http.pendingRequests.indexOf(config);
10121012
if (idx !== -1) $http.pendingRequests.splice(idx, 1);
10131013
}
10141014
}

‎src/ng/rootScope.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ function $RootScopeProvider(){
10941094

10951095
var self = this;
10961096
return function() {
1097-
namedListeners[indexOf(namedListeners, listener)] = null;
1097+
namedListeners[namedListeners.indexOf(listener)] = null;
10981098
decrementListenerCount(self, 1, name);
10991099
};
11001100
},

‎src/ngScenario/.jshintrc

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"browserTrigger": false,
1010
"console": false,
1111
"alert": false,
12-
"indexOf": false,
1312
"_jQuery": false,
1413
"angularInit": false,
1514
"formatException": false,

‎src/ngScenario/Scenario.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ angular.scenario.setUpAndRun = function(config) {
112112
}
113113

114114
angular.forEach(angular.scenario.output, function(fn, name) {
115-
if (!output.length || indexOf(output,name) != -1) {
115+
if (!output.length || output.indexOf(name) != -1) {
116116
var context = body.append('<div></div>').find('div:last');
117117
context.attr('id', name);
118118
fn.call({}, context, $runner, objModel);

‎src/ngScenario/browserTrigger.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@
33
(function() {
44
var msie = parseInt((/msie (\d+)/.exec(navigator.userAgent.toLowerCase()) || [])[1], 10);
55

6-
function indexOf(array, obj) {
7-
if (array.indexOf) return array.indexOf(obj);
8-
9-
for ( var i = 0; i < array.length; i++) {
10-
if (obj === array[i]) return i;
11-
}
12-
return -1;
13-
}
14-
15-
16-
176
/**
187
* Triggers a browser event. Attempts to choose the right event if one is
198
* not specified.
@@ -60,7 +49,7 @@
6049

6150
keys = keys || [];
6251
function pressed(key) {
63-
return indexOf(keys, key) !== -1;
52+
return keys.indexOf(key) !== -1;
6453
}
6554

6655
if (msie < 9) {

‎test/.jshintrc

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"map": false,
5757
"size": false,
5858
"includes": false,
59-
"indexOf": false,
6059
"arrayRemove": false,
6160
"isLeafNode": false,
6261
"copy": false,

‎test/helpers/matchers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ beforeEach(function() {
167167

168168

169169
toBeOneOf: function() {
170-
return indexOf(arguments, this.actual) !== -1;
170+
return Array.prototype.indexOf.call(arguments, this.actual) !== -1;
171171
},
172172

173173
toHaveClass: function(clazz) {

‎test/helpers/testabilityPatch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function sortedHtml(element, showNgClass) {
222222
var value = node.style[css];
223223
if (isString(value) && isString(css) && css != 'cssText' && value && (1*css != css)) {
224224
var text = lowercase(css + ': ' + value);
225-
if (value != 'false' && indexOf(style, text) == -1) {
225+
if (value != 'false' && style.indexOf(text) == -1) {
226226
style.push(text);
227227
}
228228
}

‎test/ng/httpBackendSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('$httpBackend', function() {
2525
while (len--) fakeTimeout.fns.shift()();
2626
};
2727
fakeTimeout.cancel = function(id) {
28-
var i = indexOf(fakeTimeout.ids, id);
28+
var i = fakeTimeout.ids.indexOf(id);
2929
if (i >= 0) {
3030
fakeTimeout.fns.splice(i, 1);
3131
fakeTimeout.delays.splice(i, 1);
@@ -50,7 +50,7 @@ describe('$httpBackend', function() {
5050
fakeDocument.$$scripts.push(script);
5151
}),
5252
removeChild: jasmine.createSpy('body.removeChild').andCallFake(function(script) {
53-
var index = indexOf(fakeDocument.$$scripts, script);
53+
var index = fakeDocument.$$scripts.indexOf(script);
5454
if (index != -1) {
5555
fakeDocument.$$scripts.splice(index, 1);
5656
}

0 commit comments

Comments
 (0)
This repository has been archived.