function function1(format) {
var regexp = /[<>]/g;
//Here the parameters are matched string,
//the position and the original text
var str = format.replace(regexp,function(match,position,originalText){
return match;
});
return str;
}
function function2(format) {
var regexp = /:(\w+)/g;
//Here the parameters are matched string,
//something like stripped string, and the position
var str = format.replace(regexp,function(match,stripped,position){
return match;
});
return str;
}
console.log(function1('<hello>'));
console.log(function2(':url :method'));
I got the first function from #Professional JavaScript for Web Developers#, and the second function from #NodeJS in Action#. You can see that the call back function for replace is not consistent. Why?