Porting code to ES5 standards mode scripts
ES5 standards mode catches errors that compatibility mode allows.
Things to watch for when porting code from existing scripts to new scoped scripts using ES5 standards mode.
ECMAScript5 evaluates the term new Boolean(false) to true. In compatibility
mode, it evaluated to false.
ECMAScript5 throws an EcmaError when a non-existent property is referenced. In compatibility mode no error was thrown.
ECMAScript5 throws an EcmaError when a non-existent function is called. In compatibility mode, no error was thrown.
ECMAScript5 correctly handles new lines. In the past, a newline character after a comment was
recognized, which is wrong. In this example, in compatibility mode, all three functions are
called. In ECMAScript5, only the first function is
called.
var expr = doFoo(); // do foo
doBar(); // do bar
finish(); // all done
eval(expr);
ECMAScript5 correctly handles postfix increment and decrement. In this example, in
compatibility mode, the variable x gets the incremented value, which is
wrong.
var x = gr.limit++;