Skip to content

Commit 756d394

Browse files
committed
Add the indexOf method to the array prototype for older browsers.
1 parent 45f3468 commit 756d394

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

angular/app/js/app.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
'use strict';
22

3-
// Declare app level module which depends on filters, and services
4-
angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers']).
5-
config(['$routeProvider', function($routeProvider) {
6-
}]);
3+
angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers'])
4+
5+
.run(function() {
6+
if (!Array.prototype.indexOf) {
7+
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
8+
'use strict';
9+
if (this == null) {
10+
throw new TypeError();
11+
}
12+
var n, k, t = Object(this),
13+
len = t.length >>> 0;
14+
15+
if (len === 0) {
16+
return -1;
17+
}
18+
n = 0;
19+
if (arguments.length > 1) {
20+
n = Number(arguments[1]);
21+
if (n != n) { // shortcut for verifying if it's NaN
22+
n = 0;
23+
} else if (n != 0 && n != Infinity && n != -Infinity) {
24+
n = (n > 0 || -1) * Math.floor(Math.abs(n));
25+
}
26+
}
27+
if (n >= len) {
28+
return -1;
29+
}
30+
for (k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); k < len; k++) {
31+
if (k in t && t[k] === searchElement) {
32+
return k;
33+
}
34+
}
35+
return -1;
36+
};
37+
}
38+
})
39+
40+
;

0 commit comments

Comments
 (0)