I'm making a Flex project, using the Cairngorm library, and trying to keep the code in a good MVC structure. I just added some code to add a prototype function to a built-in class (I added the method "contains" to Array), and I'm wondering what you would consider the best-practice for where to put this code in my project structure?
R – Best place to put prototype code in Flex project
actionscriptapache-flexcairngorm
Best Answer
In my honest opinion, it would be best to subclass or compose on Array, instead of modifying its prototype. Modifying the prototype can lead to confusion in the maintenance phase, which is one of the main reasons for using a framework like Cairngorm.
If creating a new class doesn't suit you, then also consider creating a utility class.
Flex actually already has a utility class called ArrayUtil and a function which does what you want:
ArrayUtil.getItemIndex
.Tutorial