title: Optimizing and implementing lengthy arrays of functions in Javascript
body: <p>I'm currently implementing an emulator in Javascript, the memory model of the emulated platform is rather complex, so I'm having my reads and writes go via an array of functions, for example: </p>
  
  <pre><code>var MRead = [];
  ReadBiosSpace = function(addr) { return (EnableBios ? BIOS[addr] : ROM[addr]); };
  for (i = 0; i &lt;= 0xFF; i++) { MRead[i] = ReadBiosSpace; };
  function Read(addr) { return MRead[addr](addr); };
  </code></pre>
  
  <p>because obviously the Read and Write functions will be called extremely often (at least once per instruction, the main execution is <code>Operators[Read(ProgramCounter)]()</code> ) they are extremely performance sensitive. </p>
  
  <p>Are there any performance optimizations that can be done? is this the best method? </p>