views:

72

answers:

4

In Flex ActionScript, a new object can be instantiated via the parameterless constructor with or without (). Example:

var array:ArrayCollection = new ArrayCollection()

or

var array:ArrayCollection = new ArrayCollection

Is there a difference between the two? Is one preferred over the other?

+2  A: 

I think there is no difference functionally, but I like having the () just because of convention.

CookieOfFortune
A: 

Interesting point. Until your question I had never even tried passing a class to the "new" operator without a closure to indicate I was calling the constructor. I just tried it without and it works, but I wouldn't feel comfortable doing it that way.

Robusto
A: 

if your not going to do anything with the constructor, then you don't even need to go that far:

var array:ArrayCollection;

would declare your variable just fine.

There is probably no real difference as the constructor is probably a magic method that will automagically be called when the class is called.

invertedSpear
This just defines/declares the variable, it does not instantiate an instance of an ArrayCollection. Until instantiated the variable will be undefined.
walpolea
thanks for the info walpolea. I corrected my answer.
invertedSpear
A: 

I don't know of any differences between these two ways of instantiating an object, however convention would lean towards using (). Think about when you instantiate an object that requires parameters sent into the constructor var e:Event = new Event('EventType');, having the parentheses even when left empty tells you that nothing is getting passed in.

walpolea