Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ JavaScript ] 隔離作用域,不互相影響的方式 #10

Open
veraaaaaLiu opened this issue Mar 6, 2024 · 0 comments
Open

[ JavaScript ] 隔離作用域,不互相影響的方式 #10

veraaaaaLiu opened this issue Mar 6, 2024 · 0 comments

Comments

@veraaaaaLiu
Copy link
Owner

veraaaaaLiu commented Mar 6, 2024

讓他形成閉包,互不影響

;(function(window, document, undefined){
  .
  .
  .
})(window, document)

;(function(window, document, undefined){ ... })(window, document);
這是一個 IIFE,用分號開始,以確保在連接其他可能存在的程式碼時不會造成問題。
這個函式接受三個參數:window、document、以及undefined(這裡 undefined 是參數名稱,但實際上傳遞的值是 undefined)。
這些參數是為了防止在程式碼執行期間被重新定義。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant