javascript - Assigning Object in function to Variable or call setState w/o this? -


i'm sure rather simple, me being new js , react can't seem find answer this.

basically, have function uses jq animate method act counter of sorts. function looks this:

$({countnum: 99}).animate({countnum: 1000}, {      duration: 2000,      easing:'linear',      step: function() {       var counter = math.floor(this.countnum)       console.log(counter)      },      complete: function() {        return 'counter done';      }  }); 

i trying setstate within step can simulate counter on app counts specific number. in order set state need bind this object in animate function, can't figure out how access countnum increases.

any ideas? or approaching totally wrong.

you can assign "this" specific variable before entering in callback

var _mythis = this; 

and use "_mythis" call member function/variable

_mythis.myjqfct(); 

but i'm not sure it's need in case.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -