Qooxdoo: How to use qx.lang.normalize.Array class?

59 views Asked by At

I can't figure out how to use the qx.lang.normalize.Array class. More specific problem I have with the map function. Here is my attempt

var arr1 = [1, 2, 3, 4];

// I am sure this is wrong
arr1 = qx.lang.normalize.Array.map(function(item, index, arr1){
  return item * 2;
},this);
this.debug("arr1: " + arr1);

var arr2 = [1, 2, 3, 4];

// but this works
arr2 = arr2.map(function(item){
  return item * 2;
},this);
this.debug("arr2: " + arr2);

http:// tinyurl.com/hzervvt

In the debug calls arr1 is empty while arr2 works as expected. From the documentation is not clear how it should be called.

Also another question is: should I use that class or it is not needed any more for the modern browsers?

UPDATE: After some searching I found this test file. I see there is no special mention of qx.lang.normalize.Array except for the @require in the documentation block. Does this mean the normalization happens automatically and in my code above, the second call to map() could be from that class?

1

There are 1 answers

0
johnspackman On BEST ANSWER

You should not use qx.lang.normalize.* directly at all - they are polyfills and exist so that when an old or buggy browser is encountered, Qooxdoo will add the methods from qx.lang.normalize.Array into the global Array.

This allows you to write code (like arr2.map...) which really should work in all browsers, and Qooxdoo will quietly (and automatically) fix any browsers which are broken.