Quote:
Originally Posted by Rapidwolve
Enum is useful because it can be used in ways like this:
PHP Code:
enum key{
F9 = 122,
F10 = 123,
F11 = 124
}
function onKeyPressed(code, key)
{
if (code in {key.F9, key.F10, key.F11})
do_something();
}
|
I'd just do this:
HTML Code:
function onKeyPressed(characterCode)
{
temp.codesNeeded = {122, 123, 124};
if (temp.codesNeeded.index(temp.characterCode) != -1)
{
this.doPressed(temp.characterCode);
}
//Or
if (temp.characterCode in |122, 124|)
{
this.doPressed(temp.characterCode);
}
//Or even
if (temp.characterCode in {122, 123, 124})
{
this.doPressed(temp.characterCode);
}
}
I think making it an enum is pretty pointless...