score:1
Accepted answer
You can make it a function and pass it down in the function you will have access to this
:
class foo {
constructor(a){
this.a = a;
}
method1(){
var referenceToMyClass = this;
var method2 = function(){
//do something with referenceToMyClass
}
this.dragEvent = d3.drag(referenceToMyClass)
.on("drag", method2);
d3.select('target id').call(this.dragEvent);
}
}
or you can use bind:
class foo {
constructor(a){
this.a = a;
this.method2.bind(this);
}
method1(){
var referenceToMyClass = this;
this.dragEvent = d3.drag(referenceToMyClass)
.on("drag", this.method2);
d3.select('target id').call(this.dragEvent);
}
method2(){
//this refers to the object now.
}
}
Source: stackoverflow.com
Related Query
- binding d3 event in a class
- How to access original event object when d3 event binding
- dc scatter plot binding onClick event
- Access class functions from d3 event handler
- Javascript d3.js binding click event with 'immediate invoked function'
- D3.js Dc.js Binding Event listener to axis tick label
- How do I pass event variable/place a marker on the map - when binding done events in Datamaps & D3?
- d3v4 on change event real time binding data
- Always trigger event when element of a class is clicked
- javascript class instances handling event inconsistently - this/scoping confusion
- Binding an event during an update() transition
- D3 - Event binding inside another event
- How to invoke "click" event programmatically in d3?
- Attaching 'onclick' event to D3 chart background
- How can I make double click event on node in d3.js?
- Binding javascript (d3.js) to shiny
- How to use D3 selectAll with multiple class names
- Why doesn't click event always fire?
- d3.js - mouseover event not working properly on svg group
- D3.js binding an object to data and appending for each key
- D3.js check to see if a node has a class
- How to add a click event on nvd3.js graph
- Determine if Shift key is pressed during mousedown event
- Manipulate elements by binding new data
- d3.js transition end event
- D3.js - JSON data array is binding the same array element to everything
- SVG element loses event handlers if moved around the DOM
- d3 - trigger mouseover event
- nvd3.js : unable to bind onClick event with the data points in the svg
- Is there a tap and double tap event in d3.js force directed graph
More Query from same tag
- Label Not Generating For All Value In Scatter Plot D3js
- Access y value of a d3.line after interpolation
- How to use intro.js on d3.js elements
- parametrize the bounceOut ease effect in D3
- creating svg media controls buttons
- D3 Org Chart - How to make "limbs" collapse that aren't in use
- d3 treemap dynamic data not adjusting cell width/height
- How to use quantile color scale in bar graph with drill-down?
- extract the count of fields for a month in a year and export it in json for d3.js
- Major and minor ticks with different style, whole page covered D3?
- Unable to Apply CSS style to SVG text element
- How can I use d3.layout.stack with this code to draw a line chart using D3.js?
- D3 vs Scipy (Voronoi diagram implementation)
- d3.js - blank object when applying y-axis scale
- Vertically centering a circle on a responsive D3 svg
- pass form data as url to d3.json method
- dc bubble chart X axis range
- Using D3 with a multi-dimensional array/object
- Changing d3 bullet chart range
- Subset of colorbrewer set in D3
- Mathjax not rendering inline labels
- React application breaks after downloading SVG through d3_save_svg
- Clear SVG with forcegraph D3
- d3js: How does the "magic" work with fill on hover for a barchart plot?
- D3 time scale from array index
- Create a padding for the first and last data points using a time scale
- I am trying to reproduce an example with NVD3, but not working
- 2 D3.js bar charts on the same HTML. One D3 script breaks the other
- D3 stacked graphs issue with bar position on x-Axis
- How to make same axis range for numeric attributes and different axis range for ordinal group