Matt Snider JavaScript Resource

Understanding JavaScript and Frameworks

Sunday, July 20, 2008

Extending String, Revisited

In the past, I wrote an article extending the native JavaScript String Object with useful methods and also about a RegExp escape method:

String Functions
RegExp Escape

I have revisited those methods and also added several other methods to String.prototype and static methods to String that I find useful. Check out the new String.js here and the unit test here if you want to double check that it all works well on your favorite browser.

The first noteworthy change is that I have migrated the “RegExp.esc” method to “String.prototype.escapeRx”. The old “RegExp.esc” method always required that a String be passed in, so it made sense to extend String with this functionality, instead of always calling a static method and passing a string. This allowed me to also not have a dependancy on the “string.js” utility file in my “regexp.js” utility file.

The second noteworthy change, is “String.prototype.decode” Function. This was written by Jason Yiin at Mint.com and unescapes HTML and XML entities. I have had numerous issues with server-side view technologies over escaping my HTML and/or XML code, and this Function has allowed me to correct these indiscretions.

Otherwise, I believe the files are similar to the older versions, but dependencies on other utility Functions have been removed (except Core.js) and they fail more gracefully, when bad parameters are provided.

posted by Matt Snider at 1:41 pm  

2 Comments »

  1. I hear that Jason Yiin guy is a real jerk. Super cute though

    Comment by Zonk — July 21, 2008 @ 9:43 pm

  2. Haha… yeah, super cute :p

    Comment by Matt Snider — July 21, 2008 @ 11:00 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress