探索JavaScript的关闭功能

Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

“发现功能JavaScript”BookAuthority评为最佳新功能编程书籍之一

A closure is an inner function that has access to the outer scope, even after the outer scope has executed.

闭包是一个内部函数,即使在执行外部范围之后,也可以访问外部范围。

范围 (Scope)

Scope defines the lifetime and visibility of a variable.

范围定义变量的生存期和可见性。

Every time we create a function or a block {} , we create a new scope.

每次创建函数或块{} ,我们都会创建一个新范围。

Variables declared with var have only function scope. Variables declared with let and const can have function and block scope.

var声明的变量仅具有函数作用域。 用letconst声明的变量可以具有函数和块范围。

A closure is a inner function. It has access to variables from the outer scopes.

闭包是内部函数。 它可以访问外部作用域中的变量。

Variables used by the closure function live as long as the closure lives.

闭包函数使用的变量与闭包生存的时间一样长。

Closures make it easy to work with async tasks like timers, events, AJAX calls.

使用闭包可以轻松处理异步任务,例如计时器,事件,AJAX调用。

Closures create encapsulation.

封闭创建封装。

Read Functional Architecture with React and Redux and learn how to build apps in function style.

阅读具有React和Redux的功能架构,并学习如何以函数样式构建应用程序。

Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

发现功能JavaScript被称为 BookAuthority最好的新功能编程书籍

For more on applying functional programming techniques in React take a look at Functional React.

有关在React中应用函数式编程技术的更多信息,请查看 Functional React

You can find me on Medium and Twitter.

您可以在MediumTwitter上找到我。

翻译自: https://www.freecodecamp.org/news/discover-the-power-of-closures-in-javascript-5c472a7765d7/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值