Skip to content

Native Array.from is overwritten by $A which is not able to handle all cases used by the native function #338

Open
@maxwangry

Description

@maxwangry

In version 1.7.3, the native Array.from is overwritten by $A as below:

function $A(iterable) {
  if (!iterable) return [];
  if ('toArray' in Object(iterable)) return iterable.toArray();
  var length = iterable.length || 0, results = new Array(length);
  while (length--) results[length] = iterable[length];
  return results;
}

Array.from = $A;

From the definition of these two functions:
The Array.from() method creates a new Array instance from an array-like or iterable object.
However, the $A function only accepts an array-like collection (anything with numeric indices).
So $A is not able to handle other iterable objects without numeric indices such as MapIterator.

When $A try to create a new array by reading the iterable.length which does exist in some native iterable objects such as MapIterator, the result will be an array with length 0 returned back.

Hope this will be fixed soon.

Thanks,
Max

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions