Add Array.prototype.removeDuplicates only to the types needed

Mar 1, 2010 at 2:22 PM

Add Array.prototype.removeDuplicates  only to the types needed instead of for the Array base class which causes problems for any other use of Array on the page.  I did this due to some collisions and incompatibilities of this global Array type proto def.  Moving the code only to the types that use it eliminated the issues.  This change may be less performant (have not tested).  Here are the three types with the prototype added:

 

//    Comment out this line    Array.prototype.removeDuplicates = function () { for (var lbi = 1; lbi < this.length; lbi++) { if (this[lbi][0] == this[lbi-1][0]) { this.splice(lbi,1); } } }

// Add the function to each type as needed only.

    this.imageArray     = new Array();
    this.activeImage = null;
    this.imageArray.removeDuplicates = function () { for (var lbi = 1; lbi < this.length; lbi++) { if (this[lbi][0] == this[lbi-1][0]) { this.splice(lbi,1); } } }
    
    this.slideArray     = new Array();
    this.activeSlide = null;
    this.slideArray.removeDuplicates = function () { for (var lbi = 1; lbi < this.length; lbi++) { if (this[lbi][0] == this[lbi-1][0]) { this.splice(lbi,1); } } }

    this.frameArray     = new Array();
    this.activeFrame = null;
    this.frameArray.removeDuplicates = function () { for (var lbi = 1; lbi < this.length; lbi++) { if (this[lbi][0] == this[lbi-1][0]) { this.splice(lbi,1); } } }


   Also,  Remove unused Array.prototype.empty = function () { for (var lbi = 0; i <= this.length; lbi++) { this.shift(); } }