我无法理解这种JS语法:
function myFunction(a) {
if (a == "someValue") a = "";
}
这是某种速记吗?如:如果“ a”等于“ someValue”,那么将“ a”设置为空吗?
答案 0 :(得分:1)
您的代码等同于
function myFunction(a) {
if (a == "someValue")
{
a = "";
}
}
如果传递给myFunction的参数的值为“ someValue”,则将参数设置为空字符串
答案 1 :(得分:1)
这只是不带花括号的标准if statement
。您的代码与此基本相同:
if (a == "someValue") {
a = "";
}
速记将使用类似 ternary operator 这样的东西:
a = (a == "someValue") ? "" : a;
// if "a" is loosely equal to "someValue", then assign an empty string to "a",
// else leave "a" unchanged by assigning it to it's current value.