I was looking through Google Analytics, and I came across this function (pretty-printed for readability):
ha = function(a) {
var b = [];
if (Array.prototype.indexOf) return a = b.indexOf(a), "number" ==
typeof a ? a : -1;
for (var c = 0; c < b.length; c++)
if (b[c] === a) return c;
return -1
},
This looks like an Array.prototype.indexOf
polyfill. Trouble is, instead of the var b = this;
you'd expect, there is instead var b = [];
. I can't find any circumstance in which this would not return -1
.
The last time I found something like this in Google Analytics, I had just made a mistake and it was actually functional. But... I really can't see where I'm going wrong with this one.
Does this code do anything? Or does it just unconditionally return -1
?
Sandbox for testing:
var ha = function(a) {
var b = [];
if (Array.prototype.indexOf) return a = b.indexOf(a), "number" ==
typeof a ? a : -1;
for (var c = 0; c < b.length; c++)
if (b[c] === a) return c;
return -1
};
<input id="input" value="ha(5);" /><button onclick="var v=document.getElementById('input').value;console.log(v,eval(v));">Run</button>