Zee*_*ang 1 apache-flex actionscript-3
如何使函数返回*,由星,我的意思是函数能够返回任何东西,然后我可以相应地进行类型转换?
private function get_current_files_view():TileList
{
var tlist:TileList;
//switch(this[fm_model.files_display_type])
switch(vs_file_display.selectedChild)
{
case cvs_user_files:
tlist = tlist_files;
break;
case bx_shared_data:
tlist = tlist_shared_with_me;
break;
default:
throw new Error('Invalid container found');
}
return tlist;
}
Run Code Online (Sandbox Code Playgroud)
假设在这个函数中,我希望这个函数返回tilelist和datagrid(根据情况)应该改变什么.
Plz让我知道谢谢你.
您无需定义返回类型.如果你不这样做,那么你可以退回任何东西(不推荐):
private function get_current_files_view() { }
Run Code Online (Sandbox Code Playgroud)
或者,你可以定义它必须返回一些东西,但任何东西
private function get_current_files_view():* { }
Run Code Online (Sandbox Code Playgroud)
或者,如果您想要特定的话,您可以始终使用接口或基类:
private function get_current_files_view():ISomeInterface {}
Run Code Online (Sandbox Code Playgroud)
这有帮助吗?或者我完全误解了你的问题?