2017-05-21 39 views
1

我想让我的网站适合所有知名的浏览器 在所有浏览器中,我的JavaScript代码正在工作,但在Safari中无法使用。Safari:SyntaxError:使用保留字'class'

我得到一个错误的Safari:“语法错误:使用保留字‘类’的” enter image description here

enter image description here 我的代码是这样的:

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之前。 Web解决方案之一是添加“严格使用”。但它没有帮助。 任何想法?

+2

您使用的是哪个版本的Safari? – Quentin

+0

我在5.1和8上检查过,同一问题 – AlexBerd

+0

那些版本不支持'class',请在https://caniuse.com/#feat=es6-class – yuriy636

回答

4

第一个版本的Safari浏览器,以​​是版本9

您需要升级您的浏览器(或代码transpile到ES5)。

自2013年以来,Safari 5还没有安全更新。Safari 2015自2015年以来还没有安全更新。我强烈建议采取“升级”选项。

+0

查看“Show all”是否有任何“shim “这样的问题库? – AlexBerd

+0

@AlexBerd - 不需要您需要添加新的语言关键字,而不是API功能。 – Quentin