在javascript中需要帮助 [英] Need a help in javascript
问题描述
伙计们我在javascript中给出一个变量声明可以有人解释它的作用吗?
Guys I''m giving a variable declaration in javascript Can somebody explain what it does?
var operators = { "Add":1, "Sub":2, "Mul":3, "Div":4, "Equal":5 };
我需要了解这个变量背后的基本思路。这用于计算器。运算符意味着基本的数学运算符。
添加意味着加法等等。
我还需要知道分配给这些运算符的数字的含义是什么。是1,2,3,4,5)
我尽可能多地解释。如果你不能理解,请告诉我。
谢谢........
I need to basic idea behind this variable. This is used for a calculator. operator means basic mathematics operators.
Add means Addition and so on.
I also need to know the what is the meaning of numbers which are assign to those operators.(that are 1, 2, 3, 4, 5)
I try to explain as much as I can. If you can''t understand properly please say it to me.
Thank you........
推荐答案
它这是一个枚举声明:它定义了可以与变量一起使用的常量名称,而不是使用数字:
It''s an enum declaration: it is defining constant names you can use with the variable instead of using the numbers:
if (operator == operators.Mul)
比
is clearer than
if (operator == 3)
之后的数字冒号只指定名称将与之关联的数字。
The number after the colon just specifies the number that the name will be associated with.
这篇关于在javascript中需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!