String.prototype.hasAt = function(needle, pos)
{
var i = Math.min(this.length, Math.max(0, Number(pos) || 0));
var j;
var found;
for ( ; i < this.length; i++) {
if ( found ) {
if ( i - j == needle.length ) {
return j;
}
found = this.charAt(i) == needle.charAt(i - j);
} else {
found = this.charAt(i) == needle.charAt(0);
if ( found ) {
j = i;
}
}
}
return found && this.length - j == needle.length
? j
: -1;
};
var s1 = 'aababababaO_o',
l1 = 'ababaO';
alert( [
[s1.hasAt(l1), s1.indexOf(l1)]
].join('\n') );
Кто еще верит, что все так просто?