javascript - Can we omit parentheses when creating an object using the "new" operator? -
I have noticed that the objects being created like this:
const obj = new Foo;
But I thought brackets are not optional when creating an object:
const obj = new Foo ();
What is the pre-method for creating and defining objects in ECMAScript standard? What are the differences in the way of making things and later on? Is the favorite over each other?
quote 1 :
As a special case, for the
new
operator, there is no argument in the Javascript function call, allowing simplification of grammar by allowing the parent to leave. Here are some examples of using thenew
operator:o = new object; // Optional brackets left here D = new date (); ...
Individually, I always use brackets, even when the manufacturer does not take any argument.
In addition, your feelings can be hurt if you leave the parenthesis
missing '()' invokes a constructor '
, and it does not seem that tool There is no substitute for tolerating the cover of brackets.
1 David Flanagan: (page 75)
Comments
Post a Comment