setTimeout那些事儿

1、https://www.cnblogs.com/giggle/p/5346531.html

2、奇怪的setTimeout

function test(){
			console.log(1);
			setTimeout(function(){
				console.log(2);
			},3000);
			setTimeout(function(){
				console.log(3);
			},0);
			console.log(4);
		}
		test();  //1432

3、这是因为setTimeout中所执行函数中的this,永远指向window。

           var name = '!!';
           var obj = {
               name:'monkey',
               print:function(){
                   console.log(this.name);
               },
               test:function(){
                   //this.print
                   setTimeout(this.print,1000);
               }
           }
           obj.test();
//  !!  执行函数
print()



posted @ 2018-04-02 17:35  smartwange  阅读(21)  评论(0)    收藏  举报