Javascript startsWith prototype
I'd suggest using String.prototype.slice to implement startsWith like this:

String.prototype.startsWith = function(str) {
  return this.slice(0, str.length) === str
}


For type-checking (not needed in this example, but generally speaking) you might want to use the typeof operator:

if (typeof str !== 'string') return false


You can also use the instanceof operator if the value your dealing w/ isn't a literal or you need to check every value in the prototype chain, e.g. str instanceof String

haystack = this? Super-tacky ;p, but each to their own

Not sure if JS has an AIOOBE equivalent but 'blah'.charAt(6) === '' which tells me that check isn't needed.

And I'd suggest using Array iterators rather than for loops in the future:

var haystackStartsWithNeedle = needle.split('').
  forEach((v,i) =&gt; v === haystack[i]).find(v =&gt; v)


You might want to check babeljs.io. It transpiles new &amp; flavoured JS to code most browsers can use.