我想從一個匿名函數猜每個參數的類型,像與反思,但僅僅是一個函數,像類映射...如何獲取參數的函數類型?
public function guessMyArgumentType(f:Function):void {
for each (argument:* in f.arguments) {
trace(typeof(argument));
}
}
的感謝!
UPDATE
這也許是瘋狂的,但怎麼樣:
public static function guessMyArgumentType(f:Function):String {
try {
f(2);
return "int";
} catch (error:Error) {
try {
f("a");
return "String";
} catch (error:Error) {
try {
f(["uno", "dos", "tres"]);
return "Array";
} catch (error:Error) {
try {
f(new ArrayCollection(["uno", "dos", "tres"]));
return "ArrayCollection";
} catch (error:Error) {
return "WTF?";
}
}
}
}
}
確實瘋了:-) –