Im trying to find a creative way/patch in order to minimize this line :
if(myParam == '1' || myParam == 'a' || myParam == '*' || myParam == '@' || myParam == undefined || myParam == null || myParam == ' ')
{...
}
One solution is the use indexOf - but it is not cross browser (I could write my own func to behave like indexOf - but I dont want to ).
So I tried the in operator
But the in operator deals only with object properties names and indexes
So I tried this (object properties):
if(window.lala in {
'*': 0,
'a': 0,
'@': 0,
' ': 0,
undefined: 0,
null: 0
}) alert('1')
and I think it is working.
2 question please :
question #1
is it safe for property name to be [undefined] or [' '] or [null] ? will it always work ?
question #2 Is there any other solution for doing this ?
(Case/switch can be done too, I know... )