[英]What is the error in .catch inside webcam.js file
在我正在使用網絡攝像頭的應用程序中。 要訪問它我使用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);
});
是什么原因以及如何解決?
問題顯然是catch
是一個保留關鍵字 ,因此您的代碼檢查器認為這是一個錯誤。 但是,您的代碼檢查器實際上是錯誤的, catch
也是一個有效的方法調用。 也就是說,除非你是IE的舊版本。
在舊版本的IE,該代碼將失敗,因為它也有這個問題它假定一個catch
一個外部try
/ catch
無效。 我相信這個問題在IE9或IE10中已經修復,不確定。
無論如何,你可以通過在帶有括號屬性訪問權限的字符串中使用catch
來解決舊IE和其他事情的問題:
// ...
.then( function(stream) {
// ...
})
['catch']( function(err) {
// ...
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.