Использование функций стрелок с d3

Является ли это возможным? Я не уверен, так как d3 интенсивно используетthis перепривязки и это, кажется, конфликтует с ES6спекуляция.

Например, следующее работает отлично:

// Working fine
var data = [1,2,3]
var svg = d3.select('body').append('svg').attr('height', 500).attr('width', 500).style('background-color', 'orange');
var gs = svg.selectAll('g').data(data).enter();
gs.append('circle')
    .attr('cx', function () { return Math.random()*500; })
    .attr('cy', function () { return Math.random()*500; })
    .attr('r', function () { return Math.random()*100; })
    .each(function () { console.log(this); });  // this is bound to the current element in the enter selection

Пока следующее не работает как положено (this не привязан к текущему элементу в выборе ввода, ноWindow объект):

var data = [1,2,3]
var svg = d3.select('body').append('svg').attr('height', 500).attr('width', 500).style('background-color', 'blue');
var gs = svg.selectAll('g').data(data).enter();
gs.append('circle')
    .attr('cx', () => Math.random()*500)
    .attr('cy', () => Math.random()*500)
    .attr('r', () => Math.random()*100)
    .each(() => console.log(this)); // this is bound to Window object

Родственная скрипкаВот.

Ответы на вопрос(3)

Ваш ответ на вопрос