Last active
December 20, 2015 03:19
-
-
Save chengmu/6063012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var a = window.a = { | |
name : 'a' | |
}; | |
var aStr = window.aStr = 'stringA'; | |
window.a.name = 'b'; | |
window.aStr = 'stringB'; | |
var test = function (a, aStr) { | |
console.log('timeout: ', a.name); | |
console.log('timeout: ', aStr); | |
}; | |
// setTimeout(test, 100); | |
setTimeout(function () { | |
test(a, aStr); | |
}, 100); | |
console.log('outer obj:', a.name); | |
console.log('inner string:', aStr); | |
})(); | |
console.log('outer obj', a.name); | |
console.log('outer string:', aStr); | |
//闭包:a, inner: c, outer: c, timeout: a | |
//闭包:stringA, inner: stringC, outer: stringC, timeout: stringC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment