window.variableName [英] window.variableName

查看:144
本文介绍了window.variableName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览一些代码,在脚本开头我们有 var emailID = email 。稍后,代码通过 window.emailID 引用emailID。我想知道允许你通过window.variableName引用变量的规则是什么?

I am going through some code and at the beginning of the script we have var emailID = email. Later on, the code refers to emailID by going window.emailID. I am wondering what are the rules that allow you to refer to a variable by going window.variableName?

我无法在线发布我的脚本,因为它与我的工作直接相关并且会违反我的合同。

I cannot post my script online as it is directly related to my work and would violate my contract.

推荐答案

window.variableName 表示变量正在全球范围内声明。这意味着任何JS代码都可以访问此变量。使用窗口。不是必需的,但经常被用作表示变量是全局的约定。

window.variableName means that the variable is being declared at the global scope. This means any JS code will have access to this variable. Using window. is not necessary but is frequently used as a convention to denote that a variable is global.

Globals通常是要避免的。您应该在函数范围内定义变量。

Globals are generally to be avoided. You should define variables within the scope of functions.

这篇关于window.variableName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆