+ 4
Using ES6 Functions
Hey everyone! I wanted to make my entire code with ES6 features but I failed at some point. So, my questions are: - How to make the setInterval() as an arrow function, without having to come up with a name for the function itself? - Sometimes, when I make an arrow function with a variable declaration, for example: const clk = ()=>{}; I get an Uncaught reference error : Cannon access clk before initialisation. What does that even mean? https://code.sololearn.com/WVEdzbW3W5Ot/?ref=app
7 odpowiedzi
+ 4
Hi Vasilis Karapas, I found this very cool article.
(I hope it helps you)
https://googlechrome.github.io/samples/arrows-es6/
even setInterval es6 version is covered there.
+ 4
let count = setInterval(showTime, 1000);
let count = setInterval(() => showTime(), 1000);
something like this?
+ 4
Like this as well,
window.onload=()=>{
console.log("hi");
setInterval(this.onload,1000)
}
+ 3
Code works perfectly by the way. I just wanted to make some minor adjustments, to the onload function and the setInterval() to make it ES6 style.
+ 2
RKK It's a nice start. It works nicely. However, I want to link this to the window.onload function by making the window.onload ES6 style, also. So far, I was able to get the setInterval() work only by naming the window.onload function and writing it as a normal function, not an arrow one.
+ 2
RKK Thanks for the article, I'll have a look.
+ 2
Abhay Wow, I didn't know I can do that. That's awesome!