尝试使用去抖动版本的mousemove事件处理程序时,d3.event是null.我想d3.mouse在这个debounced处理程序中使用该对象,但d3.event返回null并抛出错误.我如何能够访问d3.event以下代码:
// a simple debounce function
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
};
}
// the function to handle the mouse move
function handleMousemove ( context ) …Run Code Online (Sandbox Code Playgroud)