Search code examples
magentogoogle-maps-api-3prototypejs

This site overrides Array.from() errors on Magento using prototypejs


Magento 1 use prototypejs, this library overrides Array.form line 1081 in its 1.7 version:

Array.from = $A;

This cause the following JavaScript error in the Console:

This site overrides Array.from() with an implementation that doesn't support iterables, which could cause Google Maps JavaScript API v3 to not work correctly.

Editing this core library does not seem reasonable, how do Magento developers deal with this conflict ?


Solution

  • I think I have found a solution. Replace the line array.from($A) by this :

    function isIterable(obj) {
      // checks for null and undefined
      if (obj == null) {
        return false;
      }
      return typeof obj[Symbol.iterator] === 'function';
    }
    if (isIterable($A)) {
      Array.from = $A;
    }