... 函数局部作用域(Local Function Scope); 闭包作用域(Enclosing Scope); 全局作用域(Global Scope); ...
基于1个网页-相关网页
Watch the variables being used in a function. If you notice a function using an out-of-scope variable more than once, store it in a local variable and use that instead.
仔细检查函数中所有使用的变量,如果有一个变量不是当前作用域定义的,而且使用了不止一次,那么我们就应该把这个变量保存在局部变量中,而使用这个局部变量来进行读写操作。
The calculator makes use of the local statement to declare x as a local variable that is available only within the scope of the mycalc function.
这个计算器利用 local 语句将 x 声明为局部变量,只能在 mycalc 函数的范围内使用。
Because tally is a local variable within the function, it is created anew with each call and falls out of scope and is destroyed automatically when each call returns.
由于tally是函数内的本地变量,它将在每次调用时重新创建并清空范围,并且在每个调用被返回时自动销毁。
应用推荐