Skip to content

Instantly share code, notes, and snippets.

@chengmu
Last active December 20, 2015 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chengmu/6063012 to your computer and use it in GitHub Desktop.
Save chengmu/6063012 to your computer and use it in GitHub Desktop.
(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