数据透视表日期怎么选范围_透视范围

数据透视表日期怎么选范围

by Tiffany White

蒂芙尼·怀特(Tiffany White)

透视范围 (Putting Scope in Perspective)

In JavaScript, lexical scope deals with where your variables are defined, and how they will be accessible — or not accessible — to the rest of your code.

在JavaScript中, 词法作用域处理变量的定义位置以及其余代码如何访问(或不可访问)它们。

There are two terms to think about when talking about scope: local and global. These two terms are important to understand, because one can be more dangerous than the other when declaring variables and executing your code.

在讨论范围时,要考虑两个术语:本地和全局。 理解这两个术语很重要,因为在声明变量和执行代码时,一个术语可能比另一个更为危险。

全球范围 (Global Scope)

A variable is globally scoped if you declare it outside of all of your functions. For example:

如果在所有函数之外声明变量,则该变量在全局范围内。 例如:

//global variable, i.e. global scopevar a = "foo";
function myFunction() {  var b = "bar";  console.log(a+b);}
myFunction();

When a variable is in the global scope, it can be accessed by all the code in the same JavaScript file. In this example, I’m accessing the variable a in my console.log statement, inside the myFunction function.

当变量在全局范围内时,同一JavaScript文件中的所有代码都可以访问该变量。 在此示例中,我myFunction函数内的console.log语句中访问变量a

当地范围 (Local Scope)

Local variables only exist inside functions. They are scoped to that individual function.

局部变量仅存在于函数内部。 它们仅限于该单独功能。

You can think of local variables as as any variables that fall between an opening and closing curly brace.

您可以将局部变量视为位于花括号之间的任何变量。

These local variables can’t be accessed by code outside of the function to which they belong.

这些局部变量不能由其所属函数外部的代码访问。

Take a look at this code:

看一下这段代码:

//global variable, i.e. global scopevar a = "foo";
function myFunction() {  //local variable, or local scope  var b = "bar";  console.log(a+b);}
function yourFunction() {  var c = "JavaScript is fun!";  return c;  console.log(c);}
myFunction();yourFunction();

Notice how the variables are each declared inside separate functions. They are both local variables, in local scope, and can’t be accessed by one other.

请注意,如何分别在单独的函数中声明变量。 它们都是局部变量,在局部范围内,不能彼此访问。

For instance, I can’t return b in yourFunction, because b belongs to myFunction. b can’t be accessed by yourFunction, and vice versa.

例如,我不能在yourFunction中返回b 因为b属于myFunction。 b无法通过yourFunction访问反之亦然。

If I were to try to return the value of b when calling yourFunction, I’d get “error: b is not defined.” Why? Because b doesn’t belong to yourFunction. b is outside of yourFunction’s scope.

如果在调用yourFunction时尝试返回b的值, 则会收到“ 错误:b未定义。 为什么? 因为b不属于yourFunction。 b在您的功能范围之外。

When adding nested conditionals, scope gets even more hairy. But I’ll leave that for another time.

当添加嵌套条件时,作用域变得更加毛茸茸。 但我会再等一遍。

But for now, remember the difference between global scope and local scope. And the next time you get a “is not defined” error, check the variable’s scope.

但是现在,请记住全局范围和本地范围之间的区别。 下次您遇到“ 未定义 ”错误时,请检查变量的范围。

This post also appears at https://twhite96.github.io

这篇文章也出现在https://twhite96.github.io

翻译自: https://www.freecodecamp.org/news/putting-scope-in-perspective-c9a16974c3be/

数据透视表日期怎么选范围

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值