你能在一个函数中放一个访问函数吗?例如,像这样:
function filterByCounty(data, county) {
xValue: function (d){ return d.element; },
yValue: function (d){ return d.value; }
return data.filter(function (d){
return d.County === county;
});
}
您可以在xValue
和yValue
上定义访问器,如下所示:
function filterByCounty(data, county) {
// `this` refers to the function
Object.defineProperties(this, {
xValue: {
get: () => {
return d => d.element;
}
},
yValue: {
get: () => {
return d => d.value;
}
}
});
return data.filter(d => {
return d.County === county;
});
}