R – Where to put code that defines prototypes for base types in flex

actionscript-3apache-flexprototype

I've added functions to the Date prototype and I am wondering where is the best place to put the code in a Flex project?

Best Answer

The best practice for a Flex application is to create a utility class to manipulate instances of a class rather than to change the prototype of that class. For example, you might create a com.example.utils.DateUtil class with static functions that accept Date objects as arguments. The reason you want to follow this best practice is that Flex uses the compiler's strict setting by default, and trying to access non-standard functions added to the prototype of a sealed class will throw compiler errors. The alternative, turning off strict mode, is not advisable because the compiler will not be able to optimize your code as well as it could under strict mode.