Skip to content

Commit

Permalink
oh right old IEs don't have indexOf either
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jul 26, 2013
1 parent 7de4608 commit 36d1275
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
if (depth > maxDepth && maxDepth > 0) return '...';

if (seen === undefined) seen = [];
else if (seen.indexOf(obj) >= 0) {
else if (indexOf(seen, obj) >= 0) {
return '[Circular]';
}

Expand Down Expand Up @@ -83,3 +83,11 @@ function nameOf (f) {
var m = f.toString().match(/^function\s*([\w$]+)/);
if (m) return m[1];
}

function indexOf (xs, x) {
if (xs.indexOf) return xs.indexOf(x);
for (var i = 0, l = xs.length; i < l; i++) {
if (xs[i] === x) return i;
}
return -1;
}

0 comments on commit 36d1275

Please sign in to comment.