setTimeout global variable -


this question has answer here:

var delaytime = 2000; for(var = 0; i<this.texttowrite.length; i++){   settimeout(     (       function (s){         return function () {           this.writetext += s;           console.log(this.writetext);         }       }(this.texttowrite[i])     ), delaytime)   delaytime += 2000; } 

have problem this.writetext. it's global variable when comment += s line have undefined value... (i set writetext: string = "" globaly) this.writetext reference global variable? how can access global variables in example? need assing char texttowrite object writetext 2s delay.

good day, problem can used function word.

settimeout( ((s) => {     return () => {       this.writetext += s;       console.log(this.writetext);     }   }(this.texttowrite[i]) ), delaytime) 

another way use without if global variable

 settimeout( ((s) => {     return () => {       writetext += s;       console.log(this.writetext);     }   }(this.texttowrite[i]) ), delaytime) 

hope helps.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -