ActionScript: Multiple public functions in one .as file?

泄露秘密 提交于 2020-01-14 15:06:50

问题


As I've been working with AS I've developed a collection of utility functions. For example:

$ cat utils/curried.as
package utils {
public function curried(f:Function, ...boundArgs):Function {
    function curriedHelper(...dynamicArgs):* {
        return f.apply(null, boundArgs.concat(dynamicArgs));
    }
    return curriedHelper;
}
}

And I've found that, some times, I want to keep more than one public function in each file... But ActionScript restricts me to one public definition per file, if that file defines its self as being part of a package.

So, without creating a class with static methods, how could I get more than one public function in a single .as file?


回答1:


simply put, you can't ... for a package level function declaration, you need one file per declared function ...

little side note: personally, i'd go Josh's way and stuff them into a class ... i think allowing function level declarations at all was simply to have a bit more backward compatibility to AS2 ... it's ok, for prototyping or things that'll never leave your hands ... but you imagine relying on 3-4 libraries, each exposing their functionality through package level functions? firstly, it completely spams your autocompletion (if your IDE offers one), and secondly, you always need to look at the imports to see which function comes from where ... the prefix you mentioned is actually of great advantage ... but ok, that's my opinion ...

greetz

back2dos



来源:https://stackoverflow.com/questions/1126678/actionscript-multiple-public-functions-in-one-as-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!