View Single Post
  #15  
Old 05-05-2007, 08:45 AM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
Quote:
Originally Posted by Rapidwolve View Post
Enum is useful because it can be used in ways like this:
PHP Code:
enum key{
F9 122,
F10 123,
F11 124
}

function 
onKeyPressed(codekey)
{
  if (
code in {key.F9key.F10key.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...
Reply With Quote