2017-05-24 21 views
-2

您好我有这段代码在Chrome中工作正常,但不是在IE 11中。 我想这是ES6语法,但不是很确定。ES6的JS代码不工作在IE 11的地图()

var buf2Hex = function(buffer) { 
    //return Array.prototype.map.call(new Uint8Array(5).join('00').concat(buffer.data.toString(16)).slice(-2)).join(''); 

    return Array.prototype.map.call(new Uint8Array(buffer.data), x=>('00'+x.toString(16)).slice(-2)).join(''); 
} 

评论行是我尝试过但没有工作。

如何使它适用于IE?

+0

它怎么样?你的控制台是否有错误? –

+1

我不认为问题是[map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map?v=example),它有自IE9以来一直支持,是的,[箭头函数](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)('=>()')是ES6,并且是不支持IE浏览器(但我认为你已经明白了) –

+0

关于错误,我在IE中得到了这个:错误:[ng:areq] http://errors.angularjs.org/1.2.16/ng/areq? p0 = MyCtrl&p1 = not%20a%20function%2C%20got%20undefined如果我拿出这个函数,页面加载没有错误。 – user3552178

回答

0
var buf2Hex = function(buffer) { 
    return Array.prototype.map.call(new Uint8Array(buffer.data), function(x) { 
     return ('00' + x.toString(16)).slice(-2); 
    }).join(''); 
    //return Array.prototype.map.call(new Uint8Array(buffer.data), x=>('00'+x.toString(16)).slice(-2)).join(''); 
}