Note to self... String.split borked


I’m writing this one down because despite being burned by it before I still haven’t learned my lesson and got caught out once again. I thought that perhaps posting it up here would finally prompt me to remember it.

String.prototype.split with a regular expression has for a long time generally been stuffed across the major browsers. This has been documented before, Steven Levithan even has a nice replacement available.

Whilst there are issues in several browsers, the biggest pain-in-the-butt award though has to go to… wait for it… IE.

Why does "...".split(/\\./) not produce the same result as "...".split(".")?

I know the old ES3 spec had some issues but really… aneurysm inducing stuff.



CoffeeScript in Action


CoffeeScript in Action book cover

I'm the author. Get it from Manning.