0
下面的代碼會拋出一個未定義的錯誤,「變量API未定義」:實例化的內部條件的新組件實例將是不確定的
public string function foo() {
var bar = "";
if (somecondition) {
var api = new some.path.to.component();
bar = api.baz();
}
return bar;
}
雖然下面將正常工作:
public string function foo() {
var bar = "";
var api = new some.path.to.component();
if (somecondition) {
bar = api.baz();
}
return bar;
}
試圖通過預定義該變量解決它顯示它不會被重新分配,並會拋出「無法在java.lang.String類型的對象上調用方法查找」:
public string function foo() {
var bar = "";
var api = "";
if (somecondition) {
api = new some.path.to.component();
bar = api.baz();
}
return bar;
}
CF9.1 bug?語言功能?顯然,我只想創建組件,如果條件爲真,所以儘管後者起作用,但感覺有點浪費。
有趣 - 聽起來像一個bug –
我很想看到實際的代碼(包括你正在實例化的組件的init方法),而不是foobarbaz的東西。 –
- > https://bugbase.adobe.com/pls,thx – Henry