在使用我们的开发团队的一些as2代码的过程中,我遇到了一些令人困惑的声明,其中变量被设置为自己。 我有没有想到这种冗余的原因?
我说的字面意思是这样的:
function timeLine(x,w){ x = x; p = ((x) * 100) / w; t = v.totalTime; n = (t * p) / 100; n = n;我错过了什么? (当我们在它的时候,(x)是什么?我认为它曾经是(x + z)...)
In the course of working with some as2 code from our dev team, I came across a baffling handful of statements where variables were set to themselves. Is there some reason for such a redundancy that I'm not thinking of?
I'm talking literally like this:
function timeLine(x,w){ x = x; p = ((x) * 100) / w; t = v.totalTime; n = (t * p) / 100; n = n;What am I missing? (While we're at it, what's with (x)? I assume it used to be (x + z)...)
最满意答案
为什么函数会声明myVariable = myVariable; ?
因为编写它的程序员不称职。 你没有遗漏任何东西,无论谁写的代码最初都不知道他们在做什么。
如果那是AS3代码,它们可能是从函数参数设置一个类变量,但最好用显式方法明确表示变量是不同的:
function foo(bar, baz) { this.bar = bar; this.baz = baz; }此外,AS3具有可能导致副作用的存取器和增变器。 如果是这种情况,程序员不仅会不称职,而且也会很危险。
Why would a function state myVariable = myVariable;?
Because the programmer who wrote it was incompetent. You're not missing anything, whomever wrote that code originally didn't know what they were doing.
If that was AS3 code, it might be possible that they're setting a class variable from the function parameter, but that's best done explicitly using this to show that the variables are different:
function foo(bar, baz) { this.bar = bar; this.baz = baz; }Additionally AS3 has accessors and mutators that could cause side-effects. If this was the case, the programmer would not just be incompetent, but dangerous as well.
更多推荐
发布评论