The MDN priority table is not entirely correct; the new operator and property access operators are part of the non-terminal MemberExpression in the grammar. Since they are left-associative operators,
new something.something
estimated as
(new something).something
Here is the relevant part of the specification.
Therefore, in your approximate expression
new Date().getTime()
whole left side . parsed as an expression of MemberExpression. What is this expression of MemberExpression? This is a new MemberExpression production, so itβs deeper in the parsing tree and gives us left-associative behavior.
edit is something else I was just thinking about. Let them say that we have an object:
var obj = { findConstructor: function(name) { return window[name]; } };
Now try this expression to get the time using this object:
new obj.findConstructor("Date")().getTime()
This will give you an error. (I'm here on thin ice :) This is because he analyzes it as
new (obj.findConstructor("Date")().getTime)()
which obviously won't work. Instead, you need to add explicit brackets:
(new obj.findConstructor("Date")()).getTime()
source share