我需要理解下面由其他人编写的 java 脚本代码。 你能告诉我下面一行是什么意思吗(特别是第四行)。? 这是一条很长的线(直到;)。 这不是一个谜题。 这是一个购物应用程序的代码,实际使用中(未更改)。
function trackMetrics(a,b,c,d)
{
var e=a,f=b,g=c,h=d;
typeof a=="object"&&(a.type!=null&&(e=a.type),a.action!=null&&(e=a.action),a.data!=null&&f=a.data),a.map!=null&&(g=a.map),a.load!=null&&(g=a.load)),typeof f=="object"&&(f.data!=null&&(f=f.data),f.map!=null&&(g=f.map),f.load!=null&&(h=f.load)),typeof g=="object"&&(g.map!=null&&(g=g.map),g.load!=null&&(h=g.load));
最佳答案
嗯,目前,它意味着 SyntaxError
因为它有一个不匹配的 )
就在之前:
typeof f=="object"
但是,它似乎正在使用 comma operator对多个语句进行分组(相对于 ;
)并使用 &&
的 short-circuiting作为 if
语句的替代。
if (typeof a == "object") {
if (a.type != null)
e = a.type;
if (a.action != null)
e = a.action;
if (a.data != null)
f = a.data;
}
if (a.map != null)
g = a.map;
// etc.
关于Javascript 复杂的 "typeof"表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17599711/