PDA

View Full Version : [FIXED] Ext.Array.from() with function gives empty array



neonova
22 Sep 2011, 12:28 PM
REQUIRED INFORMATION

Ext version tested:

Ext 4.0.2a
Ext 4.0.6

Browser versions tested against:

FF6.0.2
Chrome 14

Description:

When passing a function to Ext.Array.from, an empty array is returned, instead of an array containing the function passed in.

Steps to reproduce the problem:

Call Ext.Array.from with a function as the first argument.

The result that was expected:

An array containing the function is returned

The result that occurs instead:

An empty array is returned

Test Case:

var functionsToRun = function() { window.alert('hi'); };
functionsToRun = Ext.Array.from(functionsToRun);


HELPFUL INFORMATION

Possible fix:

This occurs because a function looks like an iterable (because it has a non-undefined property "length"), but (function(){}).length === 0, so when it's passed to Ext.Array.toArray it results in an empty array.
Inside Ext.Array.from (src/core/src/lang/Array.js:595), a raw check resulted in the desired behavior:

if (Ext.isFunction(value)) {
return [value];
}


Operating System:

Windows 7 Pro