Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9411 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Custom Array.concat for Opera fails sometimes

Reported by: mors Assigned to: sam
Priority: normal Milestone: 2.x
Component: Prototype Version: edge
Severity: major Keywords:
Cc:

Description

The following piece of code is seen in prototype (because function.argumetns is an instance of an Array in Opera)

if (Prototype.Browser.Opera){
  Array.prototype.concat = function() {
    var array = [];
    for (var i = 0, length = this.length; i < length; i++) array.push(this[i]);
    for (var i = 0, length = arguments.length; i < length; i++) {
      if (arguments[i].constructor == Array) {
        for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)
          array.push(arguments[i][j]);
      } else {
        array.push(arguments[i]);
      }
    }
    return array;
  }
}

The problem: what if arguments[i] in the second loop is undefined or null? This affects this website http://www.zenggi.com/browse/CATEGORIES/DRESSES/1381/Sophie+Dress.html The color button don't work.

The solution is very simple. Change if (arguments[i].constructor == Array) { to if (arguments[i] && arguments[i].constructor == Array) {

Thanks :p

Change History

10/14/07 14:12:41 changed by Tobie

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [7226].