javascript
探索JavaScript的关闭功能
Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!
“發(fā)現(xiàn)功能JavaScript”被BookAuthority評為最佳新功能編程書籍之一 !
A closure is an inner function that has access to the outer scope, even after the outer scope has executed.
閉包是一個內(nèi)部函數(shù),即使在執(zhí)行外部范圍之后,也可以訪問外部范圍。
范圍 (Scope)
Scope defines the lifetime and visibility of a variable.
范圍定義變量的生存期和可見性。
Every time we create a function or a block {} , we create a new scope.
每次創(chuàng)建函數(shù)或塊{} ,我們都會創(chuàng)建一個新范圍。
Variables declared with var have only function scope. Variables declared with let and const can have function and block scope.
用var聲明的變量僅具有函數(shù)作用域。 用let和const聲明的變量可以具有函數(shù)和塊范圍。
A closure is a inner function. It has access to variables from the outer scopes.
閉包是內(nèi)部函數(shù)。 它可以訪問外部作用域中的變量。
Variables used by the closure function live as long as the closure lives.
閉包函數(shù)使用的變量與閉包生存的時間一樣長。
Closures make it easy to work with async tasks like timers, events, AJAX calls.
使用閉包可以輕松處理異步任務(wù),例如計時器,事件,AJAX調(diào)用。
Closures create encapsulation.
封閉創(chuàng)建封裝。
Read Functional Architecture with React and Redux and learn how to build apps in function style.
閱讀具有React和Redux的功能架構(gòu),并學(xué)習(xí)如何以函數(shù)樣式構(gòu)建應(yīng)用程序。
Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!
發(fā)現(xiàn)功能JavaScript被稱為 BookAuthority最好的新功能編程書籍 !
For more on applying functional programming techniques in React take a look at Functional React.
有關(guān)在React中應(yīng)用函數(shù)式編程技術(shù)的更多信息,請查看 Functional React 。
You can find me on Medium and Twitter.
您可以在Medium和Twitter上找到我。
翻譯自: https://www.freecodecamp.org/news/discover-the-power-of-closures-in-javascript-5c472a7765d7/
總結(jié)
以上是生活随笔為你收集整理的探索JavaScript的关闭功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到和媳妇结婚怎么回事
- 下一篇: javascript 分号_让我们谈谈J