When I console.log(this.showBox)
within the setTimeout()
, the console.log()
returns undefined
, which is different from the false
that I was expecting. May I know if the setTimeout()
makes the this.keyword
unaccessible? Thanks!
<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>