I have a JS class where I'm using D3. I've created a button element that I need to execute a class function upon being pressed. What is the proper way to do this?
class MyClass{
...
foo(bar){
d3.select("button").on("click",function(){ this.print(bar) });
}
print(text){
console.log(text);
}
}
As far as I know, going within the scope of function(){..} loses the binding of this and the instance of MyClass, because it claims that this.print() is not a function.