views:

272

answers:

1

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?

+3  A: 

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 ...

back2dos
Thanks – I hadn't considered, eg, the autocomplete spam.
David Wolever