Changing array access to use correct method.

Changing JS access to use the correct method of accessing arrays. Store
the array length into a local variable before running the loop, this
speeds up the script slightly.

Declare class constants outside of the constructor as prototypes, this
saves initialization time when objects are instantiated.