Reputation: 13
What is the correct way of creating instance of the class and directly call the method?
normally I use:
var obj = new Class();
obj.method();
if I want to call the method without creating a new variable which way is correct and what is difference between these options?
new Class().method()
or(new Class()).method()
When and why should I use 1. or 2. option?
thanks a lot
Upvotes: 1
Views: 34
Reputation: 943686
There is no practical difference between those two options.
The parentheses are redundant, just as they are in the expression (1 + 2) + 3
.
Upvotes: 1