Safari: SyntaxError: Use of reserved word 'class'

Safari: SyntaxError: Use of reserved word 'class'

我正在努力使我的网站适合所有知名浏览器 我的 JavaScript 代码在所有浏览器中都有效,但在 Safari 中无效。

我在 Safari 中遇到下一个错误:"SyntaxError: Use of reserved word 'class'"

我的代码是这样的:

    class _MontInit {
    constructor() {}
    sendXMLHTTPRequest(url, data, method, callback, error) {
        var xmlHTTP = new XMLHttpRequest(); // new HttpRequest instance 
        xmlHTTP.open(method, url);
        xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
        xmlHTTP.onload = callback;
        xmlHTTP.onerror = error;
        xmlHTTP.setRequestHeader('Cache-Control', 'no-cache');
        xmlHTTP.send(data);
    }
}

错误位置在 MontInit 之前的 class 个字上。 Web 上的解决方案之一是添加 "use strict"。但它没有帮助。 有什么想法吗?

support ES6 Classes 的第一个 Safari 版本是版本 9。

您需要升级浏览器(或将代码转译为 ES5)。

Safari 5 自 2013 年以来没有安全更新。Safari 8 自 2015 年以来没有安全更新。我强烈建议选择 "upgrade" 选项。