Answer the question
In order to leave comments, you need to log in
How to correctly format this with such a construction?
There is a code:
this.frames = [];
this.frame = 0;
let l = this;
this.canvas.onclick = function () {
if (l.frame == l.frames.length - 1) return;
l.frame++;
l.render();
}
Answer the question
In order to leave comments, you need to log in
1) You can use arrows () => {} instead of function() {}
2) You can use bind(this) to bind the context
3) You can store the context in a closure (as in your example)
I will add to the previous answer that it is better to remake l = this into self = this this
is more generally accepted
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question