The card function in D3, confused in several functions passed in

This example is from Mike Bostock:

https://bl.ocks.org/mbostock/34f08d5e11952a80609169b7917d4172

The next line is confusing to me, and I was wondering if anyone could clarify this.

x.domain(s.map(x2.invert, x2));

Why is passed as the second argument x2? As far as I know, the second parameter is an optional argument thisArg, but since it is not needed invert, why is it passed? The code seems to work fine without it, so what am I missing?

+6
source share
2 answers

, , , GitHub # 173 / rescaleX rescaleY. :

: JavaScript. , , , , , ( ).

+2

(: , , . )


, , . , : , , ( , , ).

, thisArg map :

x.domain(s.map(x2.invert, x2));
//this bit here -----------^

, invert this .

, , :

context.select(".brush").call(brush.move, x.range().map(t.invertX, t));

thisArg:

x.range().map(t.invertX, t)
//thisArg ---------------^

, invertX, invertX this:

invertX: function(x) {
    return (x - this.x) / this.k;
}

: invert invertX - , , , D3, thisArg x2.invert, , , .

, thisArg. :

x2.invert, x2
|          |
t.invertX, t
0

All Articles