js 作用域的理解

var x = 5
function a(){
    function b(){
        function c(){
            alert(x); //这里是原始操作
        }
        c();
    }
    b();
}

a();

其实     当执行到alert(x)时  他会先找自己的x      myc.x   找不到?   那就  this.x吧    
this   是b传过来的  这个时候   this.x = myb.x     还是找不到?   那在相对于b  的this.x  
这里的this  是相对b的  是从a  传过来的      this.x = mya.x   还是找不到   哎      在找相对于a  的this.x
这时候的this   就是全局的了     this.x = window.x      哈哈  终于找到了  window.x = 5  
瞬间好幸福有木有      D-:   :-D

猜你喜欢

转载自595953668.iteye.com/blog/2317233