PDA

View Full Version : [OPEN] ES 3 support for Array.prototype.reduce



Dumas
14 Oct 2013, 8:23 AM
REQUIRED INFORMATION

UPDATE: This is not a bug, this is a suggestion for a documentation enhancement:
Please add at the top of the Array.reduce documentation "Note: This function is not available in Internet Explorer 6 and 7, since it was introduced in the ECMAScript 5 standard."

Ext version tested:

Ext JS 4.2.1.883
Browser versions tested against:

IE 6 and IE 7
DOCTYPE tested against:

HTML 4
Description:
ES 3 doesn't include the function Array.prototype.reduce. This function can easily be added for IE 6 and IE 7, using MDN (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce#Compatibility).

Since the Ext JS documentation does mentions this function (http://docs.sencha.com/extjs/4.2.1/#!/api/Array-method-reduce) on the Array prototype, I would expect it to add compatibility, but running [].reduce returns undefined in IE 7.

Steps to reproduce the problem:

Open IE 7 and execute [].reduce
The result that was expected:
function

The result that occurs instead:
undefined

Test Case:


[].reduce


HELPFUL INFORMATION

Debugging already done:
There is no code correlating to the documentation here (http://extjs.local.com/docs/source/Array.html#Array-method-reduce), simply adding this snippet (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce#Compatibility) fixes the problem.

Possible fix:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce#Compatibility
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce#Compatibility)
Additional CSS used:
none

Operating System:
WinXP Pro

LesJ
14 Oct 2013, 10:12 AM
This is more of a feature request, but it would be nice to have especially if added to the MixedCollection class.

See how it's implemented in Lo-Dash (http://lodash.com/docs#reduce) and Underscore (http://underscorejs.org/#reduce)

Dumas
14 Oct 2013, 10:30 AM
No, this is not a feature request.

Ext JS claims to work with "Internet Explorer 6+", the documentation claims that Array.reduce works. So clearly the code does not match the API. Therefore this is a bug.

LesJ
14 Oct 2013, 10:43 AM
>>> the documentation claims that Array.reduce works

What documentation? Ext.Array doesn't implement the reduce polyfill. I don't see why this would be a bug. At worst this is a missing feature.

I consider Underscore and Lo-Dash reference utility libraries in this area. They don't provide the Array.reduce polyfill, so I'd question why it would be needed in Ext.Array.

The Array.reduce documentation is a JavaScript doc, not Ext JS.

http://docs-origin.sencha.com/extjs/4.2.2/#!/api/Array

Dumas
14 Oct 2013, 11:28 AM
Hmm... for me if a function is described in the documentation (here (http://extjs.local.com/docs/index.html#!/api/Array-method-reduce)), this function should work in all supported browsers.

If Ext JS really doesn't touch the reduce function at all, and it is supposed to break in ES 3 implementation, then why does Ext JS mention this function at all?
There are many ES 5 function, Ext JS is not mentioning, in my understanding Ext JS mentions the function which they make sure work on all there deploy environments. Otherwise, what's the point of having this in the docs anyway? For some general information I can use MDN or some other resource.

I hope I could explain my thoughts a bit better. From my understanding, the docs should only talk about things which work in all supported browsers.

LesJ
14 Oct 2013, 11:35 AM
I don't quite understand why Sencha documents JavaScript. I never use this documentation. If I needed general JavaScript doc, I'd search elsewhere, not in the Sencha doc.

eric.cook
14 Oct 2013, 1:31 PM
The docs for Array.prototype.reduce specifically state: NOTE: This method is part of the ECMAScript 5 standard.

I can see how one could assume that the presence of native object documentation implies that Ext JS provides extensions to those native objects to ensure compatibility. To reduce further confusion, I suggest that these docs should carry some sort of notice to the effect of "These documents are for reference only."

Ext JS stopped modifying native prototypes, but having Ext.Array.reduce would be nice.

Gary Schlosberg
14 Oct 2013, 1:38 PM
Thanks for the report! I have opened a feature request in our bug tracker.

Dumas
14 Oct 2013, 1:38 PM
Hmm... ok, you are right. I missed that note.

If they are not modifying anything at all I don't see any reason for this documentation. Anyway. In that case I think the best solution would be to add add as first documentation line: "Note: This function is not available in Internet Explorer 6 and 7, since it was introduced in the ECMAScript 5 standard.". I have updated the post.

Ext.Array.reduce would make sense.