2
if (foo) {}
if (foo != undefined) {}
if (foo != null) {}
try {foo} catch(e:Error) {}
給出一個編譯器錯誤。我如何防止這種情況?
答案(歸功於戳):
// declare the variable first
var foo:DisplayObject;
if (foo == null) {
trace('foo is null') // traces
}
謝謝,這很有道理。我確實發現你可以在現有對象中有一個空的子元素,並且不會拋出任何錯誤。 – Tom