我有一段代码,我想优化它的可读性和性能以及酷感.现在我有这个丑陋的东西:
if ( cond1 && cond2 && cond3 && !cond4)
{
// do something
}
else if ( cond1 && cond2 && !cond3 && cond4)
{
// do something
}
else if ( cond1 && !cond2 && cond3 && cond4)
{
// do something
}
else if (!cond1 && cond2 && cond3 && cond4)
{
// do something
}
else
{
// do something
}
Run Code Online (Sandbox Code Playgroud)
其中cond1,cond2,cond3和cond4是已被上面的代码块之前初始化布尔值.我想让它更快,更简单,更酷.
我正在考虑这样做:
int val = (cond1 ? …Run Code Online (Sandbox Code Playgroud) 我是一名入门级的 Web 开发人员,我正在努力确保我理解我所做的一切背后的 HTML“逻辑”(如果有的话),而不是在我把我的页面装进去后才继续前进我打算怎么看。
例如,我希望一个textarea对象在一个特定的 内水平居中div,所以我给了div这个属性text-align: center;,我从经验中知道它会完成我的预期任务。但我想确保我完全理解为什么会这样。
任何答案都非常感谢。
有人可以帮我解决这个问题吗?在下面的代码,circx并且circy被适当地初始化,但theta总是被初始化到1!theta = 1每次加载页面时,控制台都会记录.
var circx = Math.floor(Math.random() * Number.MAX_VALUE) % papwidth;
var circy = Math.floor(Math.random() * Number.MAX_VALUE) % papheight;
/*
circx, circy: initial positions of circle on the papern
*/
var mycirc = paper.circle(circx, circy, 10);
mycirc.attr("fill","#F9C624");
var theta = Math.floor(Math.random() * Number.MAX_VALUE) % 4 + 1;
/*
theta = 1 <---> object moving at a 45-degree angle
theta = 2 <---> object moving at a 135-degree angle
theta = 3 <---> …Run Code Online (Sandbox Code Playgroud)