JavaScript split problems
During the development of some string manipulation methods we ran into some problems with the JavaScript implementation of the split method in different browsers when using regular expressions as delimiters. Other people have had this problem before and Steven Levithan has a nice article about the topic including a script which fixes the inconsistencies between the different browsers, and a test page.
We decided not to use his implementation of the split method, because we do not want to rely on third party code which we have to supply with our distribution and which might break with new browser versions coming out. Instead, we will use a work-around only containing JavaScript code which is consistent among different browsers.
That’s a very reasonable approach (not relying on features that are not natively consistent cross-browser). However, for the record, there isn’t much potential for my split method to break future browsers unless their spec compliance regresses even further. My split method follows the spec, and doesn’t do any browser sniffing, so I don’t see any real risk there.
Steve
June 19, 2008 at 9:50 pm
Hello Steve. Thank you for your putting things straight regarding your split function. The decision was mostly mine, I think. For me one of the key reasons was this: your JavaScript file wrote a new split function AND put it where the built-in split function lives.
Your new split function does useful stuff, but I’d rather it did not replace the old one, in case something breaks as a result.
I’m learning that in JavaScript programming one has to make a lot of compromises. Time will tell us, I hope, whether or not we made the right decision. Finally, thank you for the work you’ve done on cross-browser string manipulation. Very useful.
jonathanfine
June 20, 2008 at 7:45 am