Home >Web Front-end >JS Tutorial >Why Are My Arrow Functions Causing Errors in IE 11?

Why Are My Arrow Functions Causing Errors in IE 11?

Susan Sarandon
Susan SarandonOriginal
2024-12-07 08:32:12688browse

Why Are My Arrow Functions Causing Errors in IE 11?

Arrow Functions Not Supported in IE 11

The provided code utilizes arrow functions to manipulate data using d3.js, which results in a syntax error when run in IE 11. The error stems from IE 11's lack of support for arrow functions.

Solution:

To resolve the issue, replace the arrow functions with traditional function functions. The following code provides an ES5 equivalent of the original code:

g.selectAll(".mainBars")
    .append("text")
    .attr("x", function(d) {
        return d.part === "primary" ? -40 : 40;
    })
    .attr("y", function(d) {
        return +6;
    })
    .text(function(d) {
        return d.key;
    })
    .attr("text-anchor", function(d) {
        return d.part === "primary" ? "end" : "start";
    });

The above is the detailed content of Why Are My Arrow Functions Causing Errors in IE 11?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn