在一个应用程序中,我使用的是摄像头。为了访问它,我使用了webcam.js (https://pixlcore.com/)。但是,当我在eclipse中打开它时,它将错误显示为:Syntax error on token "catch", Identifier expected。小代码片段:
var self = this;
this.mediaDevices.getUserMedia({
"audio": false,
"video": this.params.constraints || {
mandatory: {
minWidth: this.params.dest_width,
minHeight: this.params.dest_height
}
}
})
.then( function(stream) {
// got access, attach stream to video
video.src = window.URL.createObjectURL( stream ) || stream;
self.stream = stream;
self.loaded = true;
self.live = true;
self.dispatch('load');
self.dispatch('live');
self.flip();
})
.catch( function(err) { //here shows error
return self.dispatch('error', "Could not access webcam: " + err.name + ": " + err.message, err);
});原因是什么,如何解决?
发布于 2016-06-02 04:57:19
问题显然是catch是一个保留关键字,因此您的代码检查器认为这是一个错误。但是,您的代码检查程序实际上弄错了,catch也是一个有效的方法调用。也就是说,除非你是一个老版本,如果IE。
在早期版本的IE中,该代码将失败,因为它还存在这样的问题,即它假定在try/catch之外的一个catch是无效的。我认为这个问题在IE9或IE10中都是固定的,不确定。
无论如何,您可以通过在带有括号属性访问的字符串中使用catch来解决旧IE和其他常见问题的问题:
// ...
.then( function(stream) {
// ...
})
['catch']( function(err) {
// ...
});https://stackoverflow.com/questions/37582833
复制相似问题