【问题标题】:This site overrides Array.from() errors on Magento using prototypejs该站点使用prototypejs覆盖了Magento上的Array.from()错误
【发布时间】:2020-02-14 05:04:18
【问题描述】:

Magento 1 使用prototypejs,该库在其1.7 版本中覆盖Array.form 第1081 行:

Array.from = $A;

这会导致控制台中出现以下 JavaScript 错误:

此站点使用不支持的实现覆盖 Array.from() 支持迭代,这可能导致 Google Maps JavaScript API v3 不能正常工作。

编辑这个核心库似乎不太合理,Magento 开发者如何处理这种冲突?

【问题讨论】:

    标签: magento google-maps-api-3 prototypejs


    【解决方案1】:

    我想我找到了解决办法。 替换线 array.from($A) 通过这个:

    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;
    }

    【讨论】:

    • 感谢您的建议。错误消失了,它没有进入 if 语句。我将把它放在我的测试环境中几周,希望它没有副作用。
    【解决方案2】:

    我们的 Public Issue Tracker 报告了一个类似问题,我们的工程团队已经解决了这个问题。根据最新评论:

    我们刚刚为此提交了更新。检查现在更加明确,将涵盖您的用例: Array.from(new Set([42]))[0] !== 42 ... warn

    这将在即将发布的每周版本中提供

    Public Issue Tracker 是 Google 内部使用的一种工具,用于在产品开发过程中跟踪错误和功能请求。它可供需要与 Google 团队就特定项目进行协作的外部公众和合作伙伴用户在 Google 之外使用。你可以在这里https://developers.google.com/issue-tracker/了解更多。

    【讨论】:

      猜你喜欢
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-15
      • 1970-01-01
      • 2015-09-09
      相关资源
      最近更新 更多