js之作用域、evenLoop 发表于 2019-10-31 作用域12345678910111213141516171819var a = [1]function fn () { a[1] = 1000 a = [10] console.log('fn:', a)}fn()console.log('window:', a)// 'fn:'[10] => 'window:'[10]var a = [1]function fn (a) { a[1] = 1000 a = [10] console.log('fn:', a)}fn(a)console.log('window:', a)// 'fn:'[10] => 'window:'[1, 1000] EvenLoop1234567891011121314151617181920setTimeout(() => { console.log('1')})var p = new Promise((res, rej) => { console.log('2') setTimeout(() => { console.log(3) }) res()})p.then(() => { console.log(4)}).then(() => { console.log(7)})setTimeout(() => { console.log(5)})console.log(6)// 2 => 6 => 4 => 7 => 1 => 3 => 5