1
2
3
4
5
6
7
8
9
10
11
12
13 |
var
scope = "global" ; function
foo() { console.log(scope); } function
bar() { var
scope = "local" ; foo(); console.log(scope); } bar(); // global // local |
1
2
3
4
5
6
7
8
9
10 |
var
scope = "global" , ns = { scope: "In object" , bar: function () { console.log(scope); // !this.scope } }; ns.bar(); //result global |
(3)
1
2
3
4
5
6
7
8
9
10
11 |
var
scope = "global" , bar = function () { var
scope = "In bar" ; return
function () { // var scope = "In anony fn"; console.log(scope); }; }; bar()(); |
深入 JavaScript(6) - 一静一动,布布扣,bubuko.com
原文:http://www.cnblogs.com/patrick-holynova/p/3576638.html