开发者

Is () requested for invoking a Flex ActionScript constructor?

开发者 https://www.devze.com 2022-12-22 22:40 出处:网络
In Flex ActionScript, a new object can be instantiated via the parameterless constructor with or without (). Example:

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 d开发者_JAVA百科ifference between the two? Is one preferred over the other?


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


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号