not an expert on js but this if-statement still tickles me because I suspect it can be written in a way more clever fashion:
if(event.value == "/")
{
event.value = "/home";
}
Suggestions?
not an expert on js but this if-statement still tickles me because I suspect it can be written in a way more clever fashion:
if(event.value == "/")
{
event.value = "/home";
}
Suggestions?
You could omit the braces:
if(event.value == "/") event.value = "/home";
Or a conditional:
event.value = event.value == "/" ? "/home" : event.value;
...but I'm not sure either of those is really "better", and a with statement you should just stay away from.
with statement I liked above, but it's evil for a few reasons - and not available in all browsers.I don't think there's a better way. You could omit the braces if your coding style guide allows you to, but it won't semantically make a difference.
The shorter event.value = (event.value == '/')?'/home':event.value; is not so good, because it makes a useless assignment when the value differs from '/'.