<!DOCTYPE html><html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title></title></head> <body> </body> <script>var name = '張三';(function () {if (typeof name == 'undefined') {var name = '李四';console.log(name);} else {console.log('hello' + name);}})()</script></html> 主要的疑慮就是為什么取不到外部的值,以及這個函數前后兩個括號各代表的是什么意思?這樣會形成閉包嗎? 勞煩哪位大佬給我解答,謝謝了~~
這個函數執行 為什么取不到外部的值
烙印99
2018-06-28 11:14:47