Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230742

Background running and variables

$
0
0

This is one of the extremely poor design decisions of JavaScript. The main heuristic I use to avoid problems like you are seeing is “never type the word function inside of one”, and your situation is a cousin of that. In C++, the compiler would throw an error until you made test a static method, at which point it would become obvious to you that you can’t access member variables. JavaScript, on the other hand, decided it would be a better idea to silently make the construct do something nobody would ever expect or want. Your best tool here is the arrow function:

setInterval(() => this.test(), 1000);

Viewing all articles
Browse latest Browse all 230742

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>