Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE11: SCRIPT438:Object doesn't support property or method 'forEach' #6511

Closed
hezhongfeng opened this issue Oct 19, 2017 · 8 comments

Comments

Projects
None yet
5 participants
@hezhongfeng
Copy link

commented Oct 19, 2017

Input Code

      let topicsDoc = document.querySelectorAll(".topic");
      let topicList = "";
      topicsDoc.forEach(function(element) {
        topicList += element.innerText;
        console.log(element.innerText);
      });

Babel Configuration (.babelrc, package.json, cli command)

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "ie >= 11"]
      }
    }],
    "stage-2"
  ],
  "plugins": ["transform-runtime"],
  "env": {
    "test": {
      "presets": ["env", "stage-2"],
      "plugins": ["istanbul"]
    }
  }
}

Expected Behavior

console some text

Current Behavior

IE11 will has en error
SCRIPT438:Object doesn't support property or method 'forEach'

Possible Solution

Context

Your Environment

software version(s)
Babel 6.22.1
node 6.11.0
npm 3.10.10
Operating System win10
@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Oct 19, 2017

Hey @hezhongfeng! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@hezhongfeng hezhongfeng changed the title IE11:`SCRIPT438:Object doesn't support property or method 'forEach'` IE11: SCRIPT438:Object doesn't support property or method 'forEach' Oct 19, 2017

@hzoo

This comment has been minimized.

Copy link
Member

commented Oct 19, 2017

This looks to be unrelated to using Babel or not? Does ie11 not support forEach on querySelectorAll? It's not anything related to changing the syntax from let to var, so you'd need to add a polyfill

@hzoo hzoo closed this Oct 19, 2017

@hzoo hzoo added the i: question label Oct 19, 2017

@Andarist

This comment has been minimized.

Copy link
Member

commented Oct 19, 2017

@hezhongfeng

This comment has been minimized.

Copy link
Author

commented Oct 20, 2017

@Andarist
Thank you for your answer.
Has any way to resolve it?

@loganfsmyth

This comment has been minimized.

Copy link
Member

commented Oct 20, 2017

The easiest thing to do would be

let topicsDoc = Array.from(document.querySelectorAll(".topic"));

since Array will have .forEach.

@hezhongfeng

This comment has been minimized.

Copy link
Author

commented Oct 20, 2017

@loganfsmyth
tks.
I will try it.

@hezhongfeng

This comment has been minimized.

Copy link
Author

commented Oct 24, 2017

@loganfsmyth
I test it and I found this is okay.

  1. for
for(var index=0;index<nodeList.length;index++)
  1. slice.call
var arr = Array.prototype.slice.call(nodeList);
@loganfsmyth

This comment has been minimized.

Copy link
Member

commented Oct 24, 2017

Yup, those are options too. They do pretty much the same thing as Array.from, assuming you have Array.from or a polyfill for it.

@lock lock bot added the outdated label May 1, 2018

@lock lock bot locked as resolved and limited conversation to collaborators May 1, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.