• <i id='7xomG'><tr id='7xomG'><dt id='7xomG'><q id='7xomG'><span id='7xomG'><b id='7xomG'><form id='7xomG'><ins id='7xomG'></ins><ul id='7xomG'></ul><sub id='7xomG'></sub></form><legend id='7xomG'></legend><bdo id='7xomG'><pre id='7xomG'><center id='7xomG'></center></pre></bdo></b><th id='7xomG'></th></span></q></dt></tr></i><div id='7xomG'><tfoot id='7xomG'></tfoot><dl id='7xomG'><fieldset id='7xomG'></fieldset></dl></div>

      <small id='7xomG'></small><noframes id='7xomG'>

      <legend id='7xomG'><style id='7xomG'><dir id='7xomG'><q id='7xomG'></q></dir></style></legend>
        <bdo id='7xomG'></bdo><ul id='7xomG'></ul>
        <tfoot id='7xomG'></tfoot>

        EcmaScript 6 的非法构造函数

        时间:2023-05-28
            <bdo id='i77Zt'></bdo><ul id='i77Zt'></ul>

                  <tbody id='i77Zt'></tbody>

                <tfoot id='i77Zt'></tfoot>

              • <i id='i77Zt'><tr id='i77Zt'><dt id='i77Zt'><q id='i77Zt'><span id='i77Zt'><b id='i77Zt'><form id='i77Zt'><ins id='i77Zt'></ins><ul id='i77Zt'></ul><sub id='i77Zt'></sub></form><legend id='i77Zt'></legend><bdo id='i77Zt'><pre id='i77Zt'><center id='i77Zt'></center></pre></bdo></b><th id='i77Zt'></th></span></q></dt></tr></i><div id='i77Zt'><tfoot id='i77Zt'></tfoot><dl id='i77Zt'><fieldset id='i77Zt'></fieldset></dl></div>
                <legend id='i77Zt'><style id='i77Zt'><dir id='i77Zt'><q id='i77Zt'></q></dir></style></legend>

                <small id='i77Zt'></small><noframes id='i77Zt'>

                1. 本文介绍了EcmaScript 6 的非法构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  首先我想说的是,我真的不知道如何解释我做了什么才能得到标题中提到的错误(uncaught TypeError: Illegal constructor).我正在使用 gulpfile 将我的 Ecmascript 6 编译为纯 Javascript.我的 gulpfile 看起来像这样:

                  First of all I would like that say that I don't really know how I can explain what I did on order to get the error mentioned in the title (uncaught TypeError: Illegal constructor). I am using gulpfile in order to compile my Ecmascript 6 to plain Javascript. My gulpfile looks like this:

                  var gulp = require('gulp');
                  var concat = require('gulp-concat');
                  var babel = require('gulp-babel');
                  
                  gulp.task('compile', function () {
                      return gulp.src(['resources/assets/js/*.js', 'resources/assets/js/components/*.js'])
                          .pipe(babel({
                                  presets: ['es2015']
                          }).on('error', logError))
                          .pipe(concat('bundle.js'))
                          .pipe(gulp.dest('public/js'));
                  });
                  
                  gulp.task('watch', function () {
                     gulp.watch('resources/assets/js/**/*', ['compile']);
                  })
                  
                  gulp.task('default', ['watch']);
                  
                  function logError(err) {
                      console.log(err);
                  }
                  

                  我有一个文件系统,在使用 Babel 编译后,所有文件都连接到一个文件 (bundle.js).

                  I have a filesystem where all files are concatenated to one file (bundle.js), after being compiled with Babel.

                  在浏览器控制台(Chrome 或 Firefox)中,错误出现并且位于下一行:

                  In the browsers console (either Chrome or Firefox), the error appears and it is located in the next line:

                  var _this = _possibleConstructorReturn(this, (Dropdown.__proto__ || Object.getPrototypeOf(Dropdown)).call(this, element));
                  

                  这是未编译的代码:

                  class Dropdown extends Node {
                  
                      constructor(element) {
                          super(element);
                  
                          this.registerEvents(['click', 'change', 'blur']);
                      }
                  
                      onClick() {
                          this.$element.addClass('clicked');
                      }
                  }
                  

                  这是同一类的编译代码:

                  And this is the compiled code of the same class:

                  var Dropdown = function (_Node) {
                      _inherits(Dropdown, _Node);
                  
                      function Dropdown(element) {
                          _classCallCheck(this, Dropdown);
                  
                          var _this = _possibleConstructorReturn(this, (Dropdown.__proto__ || Object.getPrototypeOf(Dropdown)).call(this, element));
                  
                          _this.registerEvents(['click', 'change', 'blur']);
                  
                          return _this;
                      }
                  
                      _createClass(Dropdown, [{
                          key: 'onClick',
                          value: function onClick() {
                              this.$element.addClass('clicked');
                          }
                      }]);
                  
                      return Dropdown;
                  }(Node);
                  

                  我没有使用 export default Dropdown 因为我没有在其他模块中导入模块(这不是必需的,因为每个文件都转换为一个文件,所有内容都可以访问).

                  I am not using export default Dropdown because I am not importing modules in other modules (this is not needed because every file is converted to one file, where everything is accessible).

                  我做了一些研究,人们得到这个错误的唯一原因是因为有一个大写字母是不允许的.我没有找到有关此错误原因的任何其他信息.有人知道我为什么会收到此错误吗?有人有解决方案吗?

                  I did some research and the only reason why peoeple got this error was because there was a capital letter where none was allowed. I didn't find anything else about the cause of this error. Does someone have an idea why I get this error? And does someone have a solution?

                  推荐答案

                  看起来你正在尝试扩展 DOM 的 节点.你不能这样做,它被定义为一个抽象接口,并且在浏览器中公开的主机提供的函数不能作为构造函数调用(即使是子类).

                  It looks like you're trying to extend DOM's Node. You can't do that, it's defined as an abstract interface, and the host-provided function exposed in browsers for it can't be called as a constructor (even by subclasses).

                  这篇关于EcmaScript 6 的非法构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 TypeScript 和 Babel 的 Gulp 源图 下一篇:Nodemon监视选项损坏

                  相关文章

                  最新文章

                  <small id='pusGt'></small><noframes id='pusGt'>

                  • <bdo id='pusGt'></bdo><ul id='pusGt'></ul>
                2. <i id='pusGt'><tr id='pusGt'><dt id='pusGt'><q id='pusGt'><span id='pusGt'><b id='pusGt'><form id='pusGt'><ins id='pusGt'></ins><ul id='pusGt'></ul><sub id='pusGt'></sub></form><legend id='pusGt'></legend><bdo id='pusGt'><pre id='pusGt'><center id='pusGt'></center></pre></bdo></b><th id='pusGt'></th></span></q></dt></tr></i><div id='pusGt'><tfoot id='pusGt'></tfoot><dl id='pusGt'><fieldset id='pusGt'></fieldset></dl></div>

                  1. <tfoot id='pusGt'></tfoot>
                  2. <legend id='pusGt'><style id='pusGt'><dir id='pusGt'><q id='pusGt'></q></dir></style></legend>