亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript function
給我你的懷抱
給我你的懷抱 2017-06-26 10:53:22
0
6
859
function Foo(){
            getName = function(){
                console.log(1);
            };
           return this;
        }

        var getName = function (){ 
            console.log(4)
        };



          Foo().getName(); 

Why does the above code output 1;

After foo() is run, this is output. This is the window object. Does getName in foo() become a global function expression? And the following var getName is also a function expression; why is it printed? The result is 1;

foo, after execution, is it equivalent to the following code?

getName = function(){
            console.log(1);
        };

        var getName = function (){ 
            console.log(4)
        };



          getName(); //4
給我你的懷抱
給我你的懷抱

reply all(6)
小葫蘆

When Foo is not called

window.getName = function(){
    console.log(4);
}

When calling Foo()

getName = function(){
                console.log(1);
            };
// 相當(dāng)于更改了 window.getName

After the call, return this in Foo does point to window, so the final result is 1.

扔個(gè)三星炸死你
function Foo(){
    getName = function(){
        console.log(1);
    };
    return this;
}
//全局聲明一個(gè)變量getName
var getName = function (){ 
    console.log(4)
};
//重新賦值
getName = function () {
    console.log(1)
}
//最終打印結(jié)果為1
window.getName()
黃舟

Foo().getName(); executes getName in Foo

阿神
function Foo(){
    getName = function(){
        console.log(1);
    };
    return this;
}

var getName = function (){ 
    console.log(4)
};

Foo().getName();
function Foo(){
    getName = function(){
        console.log(1);
    };
    return this;
}

var getName = function (){ 
    console.log(4)
};

getName = function () {
    console.log(1)
}

window.getName()
代言

Check console.log(Foo()), are you sure it is window?

ringa_lee

The getName in the Foo function is not declared with var, so it is global, so when Foo is run, the getName function inside the function will overwrite the one defined outside

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template