Bug: String.prototype.endsWith
Axel Rauschmayer
axel at rauschma.de
Fri Sep 23 12:18:01 PDT 2011
http://wiki.ecmascript.org/doku.php?id=harmony:string_extras
I’ve found a small bug:
String.prototype.endsWith = function(s) {
var t = String(s);
return this.lastIndexOf(t) === this.length - t.length;
};
Interaction:
> "".endsWith("/")
true
> "#".endsWith("//")
true
> "##".endsWith("///")
true
Fix (e.g.):
String.prototype.endsWith = function(s) {
var t = String(s);
var index = this.lastIndexOf(t)
return index >= 0 && index === this.length - t.length;
};
--
Dr. Axel Rauschmayer
axel at rauschma.de
twitter.com/rauschma
home: rauschma.de
blog: 2ality.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110923/c32e19ba/attachment.html>
More information about the es-discuss
mailing list