The best place to put prototype code in a Flex project

I am making a Flex project using the Cairngorm library and trying to keep the code in a good MVC framework. I just added some code to add the prototype function to the inline class (I added the method "contains" to the Array) and I'm wondering what do you think is the best practice for where to put this code in my project structure?

0


source to share


1 answer


In my honest opinion, it would be better to subclass or compose an Array instead of modifying its prototype. Modifying the prototype can lead to confusion during 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.

On the Flex actually already has utility class ArrayUtil and function that does what you want: ArrayUtil.getItemIndex

.



var obj1:Object = new Object();
var obj2:Object = new Object();
var myArray : Array = [obj1, obj2];
ArrayUtil.getItemIndex(obj1, myArray);    // returns 0
ArrayUtil.getItemIndex(obj2, myArray);    // returns 1
ArrayUtil.getItemIndex(obj3, myArray);    // returns -1

      

Textbook

+1


source







All Articles