views:

62

answers:

2

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?

A: 

Probably best to put it in a preinitialize handler for the Application - in case the prototype is used by any components as they're created.

jmreidy
+1  A: 

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.

joshtynjala