js timers and this common misunderstanding

Timer:

js timer There are two methods: setInterval (func, ms) and setTimeout (func, ms)

Difference: setInterval () is an infinite loop until a clear separation period, while setTimeout () is executed only once, so use a timer if the loop can be screened to select

The same: first interval are specified function is executed ms

this:

js jquery in this and in this

The same point: who are the called according to points to anyone.

Case 1:

  var name = "Jack" ;
         var getName = function () {
             return  the this .name; 
        } 
        var Entity = {name: "Rose" , getName: getName}; 
        the console.log (getName ()); // printed is Jack 
        the console.log (entity.getName ()); // Print out the rose

References: https: //blog.csdn.net/weixin_41615439/article/details/88697292

Guess you like

Origin www.cnblogs.com/lqc07-4-14/p/11247776.html
Recommended