Crockford's deentityify method - p.41 of The Good Parts
In a fit of self-improvement, I'm reading (and rereading) TGP by Señor Crockford. I cannot, however, understand the middlemost part of his deentityify method.

    ...
    return this.replace(...,
        function (a, b) {
           var r = ...
        }
    );

I think I understand that:

 1. this.replace is passed two arguments, the regex as the search value and the function to generate the replacement value;
 2. the a & b refer to the properties in the entity object;
 3. the return `? r : a;` bit determines whether to return the text as is or the value of the appropriate property in entity.

What I don't get at all is how the a & b are provided as arguments into `function (a, b)`. What is calling this function? (I know the whole thing is self-executing, but that doesn't really clear it up for me. I guess I'm asking how is this function being called?)

If someone was interested in giving a blow by blow analysis akin to [this][1], I'd really appreciate it and I suspect others might too.


  [1]: http://stackoverflow.com/questions/2947749/line-by-line-explanation-of-javascript-good-parts-example
Crockford's deentityify method - p.41 of The Good Parts
===

In a fit of self-improvement, I'm reading (and rereading) TGP by Señor Crockford. I cannot, however, understand the middlemost part of his deentityify method.

    ...
    return this.replace(...,
        function (a, b) {
           var r = ...
        }
    );

I think I understand that:

 1. this.replace is passed two arguments, the regex as the search value and the function to generate the replacement value;
 2. the a & b refer to the properties in the entity object;
 3. the return `? r : a;` bit determines whether to return the text as is or the value of the appropriate property in entity.

What I don't get at all is how the a & b are provided as arguments into `function (a, b)`. What is calling this function? (I know the whole thing is self-executing, but that doesn't really clear it up for me. I guess I'm asking how is this function being called?)

If someone was interested in giving a blow by blow analysis akin to [this][1], I'd really appreciate it and I suspect others might too.


  [1]: http://stackoverflow.com/questions/2947749/line-by-line-explanation-of-javascript-good-parts-example