问题
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