i need to remove the event listener. i'm calling to some method from the function executed within the event listener, so i need to use to es6 syntax. i couldn't use named functions. how can i remove the event listener
methods :
initCanvas : function(x, y, width, height) {
//do something
},
some_method : function() {
let svgObjectEl = // some logic will give the object elemenet embedding the svg
svgObjectEl.addEventListener('load', () => {
//let x,y,width, height has some value
// some code here
this.initCanvas(x, y, width, height);
});
svgObjectEl.removeEventListener('load', ??);
}
i need to remove the event listener. i'm calling to some method from the function executed within the event listener, so i need to use to es6 syntax. i couldn't use named functions. how can i remove the event listener
methods :
initCanvas : function(x, y, width, height) {
//do something
},
some_method : function() {
let svgObjectEl = // some logic will give the object elemenet embedding the svg
svgObjectEl.addEventListener('load', () => {
//let x,y,width, height has some value
// some code here
this.initCanvas(x, y, width, height);
});
svgObjectEl.removeEventListener('load', ??);
}
Share
Improve this question
edited Dec 5, 2017 at 17:38
Tomonso Ejang
asked Dec 1, 2017 at 17:55
Tomonso EjangTomonso Ejang
1,3664 gold badges16 silver badges28 bronze badges
4
- 2 You need to store it in a variable. – SLaks Commented Dec 1, 2017 at 17:57
- can you write it out. – Tomonso Ejang Commented Dec 1, 2017 at 18:11
-
1
wouldn't
<svg @load.once="listener" ...
do it ? – birdspider Commented Dec 1, 2017 at 18:29 - @birdspider No. i had to perform some logic – Tomonso Ejang Commented Dec 1, 2017 at 18:52
1 Answer
Reset to default 2Something like this maybe?
methods: {
initCanvas (x, y, width, height) {
//do something
},
some_method() {
svgObjectEl.options = { x: 12, y: 13, … }
svgObjectEl.addEventListener('load', this.listener)
},
listener(evt) {
// some code here
this.initCanvas(evt.target.options)
svgObjectEl.removeEventListener('load', this.listener)
}
}