martedì, luglio 11, 2006

Another Pearl in the Javascript World

He Done It!


After my IE setAttribute solution (get here the complete solution along with my framework)


Andrea Giammarchi wrote a solution for the replace method, now you can use replace with a function as parameter, and is Standard ECMA compatible!


Try it or Get It!


It works on IE 5.x+, FF, NN,Opera, Safari, Konqueror ,


currently I haven't the complete compatibility list because is in a test state.


Now Javascript world is more standard!!! ;)


Example:


ECMA define that the function get the follow parameters


a)the Match of Regex passed as 1st argument


b)the N submatch (also known as parenthetical matches) with 0<N<99


c)position of the match in the original string


d)the original string


so "a12b34".replace(/[0-9][0-9]/g,function(a,b,c){return (Number(a)+1);}) must return "a13b35" in all the browser ;)

Posta un commento