Вариант...
String.prototype.index = function (b) {
for (var a = -1, d = this.length, c = 0; c < d; c++) {
if (b.length > d) break;
a++;
a = b.charAt(a) === this.charAt(c) ? a : b.charAt(0) === this.charAt(c) ? 0 : -1;
if (a == b.length - 1) return c - b.length + 1
}
return a
};
var s1 = 'aababaO_o',
l1 = 'aba', l2 = 'abac', l3 = 'aa', l4 = 'O_o';
alert( [
[s1.index(l1), s1.indexOf(l1)],
[s1.index(l2), s1.indexOf(l2)],
[s1.index(l3), s1.indexOf(l3)],
[s1.index(l4), s1.indexOf(l4)]
].join('\n') )