如果我可以说:
var big = (x > 10) ? true : false;
代替:
var big;
if (x > 10) {
big = true;
}
else {
big = false;
}
我如何使这个同样更短?
var now = new Date
if (now.getHours() < 5) {
return "late night pick me up";
}
else if (now.getHours() < 9) {
return "breakfast";
}
else if (now.getHours() < 13) {
return "lunch";
}
else if (now.getHours() < 17) {
return "afternoon snak";
}
else {
return "dinner";
}
非常感谢!