Use js class

Examples brush

A brush d3 to be described, the example see:

https://bl.ocks.org/xunhanliu/6f0b46789842e9e19e6cfe9bd0b16806

Application scenarios:

When there are multiple pages on a map, each figure Moreover, the maintenance of a brush, independently of each other.

The basic structure of the class js:

// definition of class
var A = 100; class Point { constructor (X, Y) { the this .x = X; the this .y = Y;
} toString () {
return '(' + A + the this .x + ',' + the this .y + ')' ; // global variables a, still using normal } }

 Reference from: https://www.cnblogs.com/zczhangcui/p/6528039.html

Description:

1, constructor: a constructor

2, each of the foregoing methods allowed class plus function.

3, global variables can be used normally

Key:

this conflict

In this event (element) has a specific designated (whose function is triggered by this function, the function of this points to the inside of the Who (dom)). And use this in the global zone, this point window class.

Of course, in a custom class often there is only a method of binding events (such as a click event binding methods of this class) in this conflict. For this situation, can be used to avoid closures.

Such as:

       Point {class 
        constructor (DOM) { 
            d3.select (DOM) .on ( 'the Click', this ._click ( this )); 
        } 

        _Click (that) { 
            return  function () {
                 // at this point which is clicked element , that point point instance   
            } 
        } 
    }

 

Guess you like

Origin www.cnblogs.com/xunhanliu/p/10990579.html