【问题标题】:What is the error in .catch inside webcam.js filewebcam.js 文件中 .catch 的错误是什么
【发布时间】:2016-10-01 15:47:36
【问题描述】:

在我使用网络摄像头的应用程序中。为了访问它,我使用了 webcam.js (https://pixlcore.com/)。但是当我在 Eclipse 中打开它时,它显示错误为:Syntax error on token "catch", Identifier expected。小代码sn-p:

            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);
            });

是什么原因,如何解决?

【问题讨论】:

标签: javascript webcam webcam.js


【解决方案1】:

问题显然是catchreserved keyword,因此您的代码检查器认为这是一个错误。但是,您的代码检查器实际上是错误的,catch 也是有效的方法调用。也就是说,除非你是老版本的IE。

在旧版本的 IE 中,此代码将失败,因为它还存在这个问题,即假定 try/catch 之外的 catch 无效。我相信这个问题在 IE9 或 IE10 中都已修复,不确定。

无论如何,您可以通过在具有括号属性访问权限的字符串中使用 catch 来解决旧 IE 和其他具有此一般问题的问题:

// ...
.then( function(stream) {
    // ...
})
['catch']( function(err) { 
    // ...
});

【讨论】:

  • 感谢这项工作!我正在使用 ECMAScript 3,所以我认为它没有验证。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-07
  • 2017-06-25
  • 1970-01-01
  • 2011-01-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多