开发者

Is there a performance decrease from not specifying the this word in a AS3 file?

开发者 https://www.devze.com 2023-03-20 07:06 出处:网络
I know there are performance loses if开发者_StackOverflow社区 you don\'t specify variable types explicitly. Do ActionScript/Java developer in general prefer the use of the in classes or no?

I know there are performance loses if开发者_StackOverflow社区 you don't specify variable types explicitly. Do ActionScript/Java developer in general prefer the use of the in classes or no?

public function hello():void
{
   this.speaker.says("hello");
}

vs

speaker.says("hello")


There is no performance difference, it's just down to a matter of personal preference.

I prefer to use this.foo, personally. I sense I'm in the minority.


Just use the shorter form, there are no performance differences and the shorter form is generally preferred.


The only time it's really useful to use this in AS3 could be, for example in a constructor where there may be some ambiguity between the method params and the instance params:

private var foo:String;
private var bar:String;

myClass( foo:String, bar:String ) {
    this.foo = foo;
    this.bar = bar;
} 

But there is an issue of whether that is good programming style anyway.

0

精彩评论

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