Hi,
I am pretty new to javascript.
I encountered some code in “Javascript the good part” from Douglas Crockford.
There is a way to passing callback function as second argument to string.replace() method.
var entity = {
quot: '"',
lt: '<',
gt: '>'
};
var finalStr = '<">'.replace(/&([^&;]+);/g,
function (a, b) {
var r = entity[b];
return typeof r === 'string' ? r : a;
}
);
My questions are:
- How do I know what the number of parameters should be in callback function ( function(a,b) ) ?
- How do I know what will be passed in as a and b when I am defining the callback function?
Thanks in advance
David