Safari: SyntaxError: Use of reserved word 'class'

坚强是说给别人听的谎言 提交于 2019-12-11 05:18:21

问题


I am trying to fit my website to all well known browsers In all browsers my JavaScript code is working, but not in Safari.

I get next error in Safari: "SyntaxError: Use of reserved word 'class'"

my code is look like:

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

The error placement is on class word before MontInit. One of the solution over Web was to add "use strict". but it did not help. Any ideas?


回答1:


The first version of Safari to support ES6 Classes was version 9.

You need to upgrade your browsers (or transpile the code to ES5).

Safari 5 hasn't had a security update since 2013. Safari 8 hasn't had a security update since 2015. I strongly advise taking the "upgrade" option.



来源:https://stackoverflow.com/questions/44096182/safari-syntaxerror-use-of-reserved-word-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!