Whenever I use console.log(this.showBox)
inside the setTimeout()
function, it unexpectedly returns undefined
instead of false
. Could someone please explain if the setTimeout()
affects the accessibility of this.keyword
? Thank you!
<script>
import Block from "./components/Block.vue"
export default {
name: 'App',
components: {
Block,
},
data() {
return {
isPlaying: false,
delay: null,
timer: null,
reactionTime: 0,
showBox:false,
}
},
methods: {
startGame() {
this.isPlaying = true;
//this.delay = 2000 + Math.floor(Math.random(1,4000) * 4000)
this.delay = 1000
console.log(this.delay)
console.log(this.showBox)
setTimeout(function() {
console.log(this.showBox)
}, this.delay);
},
},
}
</script>