When I have something like this:
var str = \"0123\"; var i = 0; str.replace(/(\\d)/g,function(s){i++;return s;}(\'$1\')); alert(i);
Why doe
The expression
function(s){i++;return s;}('$1')
Creates the function and immediately evaluates it, passing $1 as an argument. The str.replace method already receives a string as its second argument, not a function. I believe you want this:
$1
str.replace
str.replace(/(\d)/g,function(s){i++;return s;});