简体   繁体   English

有没有办法为 ES5.1 class 分配一个匿名 function?

[英]Is there a way to assign an ES5.1 class an anonym function?

I was trying to implement ANTLR4 for a project that i'm working on and I created a Python3 parser for JavaScript by using the ANTLR4 tool.我正在尝试为我正在处理的项目实现 ANTLR4,我使用 ANTLR4 工具为 JavaScript 创建了一个 Python3 解析器。 The problem is that when I try to run the code, the following error is raised: TypeError: Assignment to constant variable.问题是,当我尝试运行代码时,会出现以下错误: TypeError: Assignment to constant variable。

TypeError: Assignment to constant variable.

The piece of code is the following: Assignment这段代码如下:赋值

      let old_lexer = Python3Lexer;
      Python3Lexer = function () {
        old_lexer.apply(this, arguments);
        this.reset.call(this);
      }

Python3Lexer is a class. Python3Lexer 是一个 class。

I am using ANTLR 4.9.2 and ECMAScript 5.1 (but I don't really know if this one is running, maybe it is the default version).我正在使用 ANTLR 4.9.2 和 ECMAScript 5.1(但我真的不知道这个是否正在运行,也许它是默认版本)。

I don't really understand what does that assignment mean and also I don't really know if it can be written on some other way.我真的不明白那个作业是什么意思,我也不知道它是否可以用其他方式写。

Thanks in advance.提前致谢。

Using ANTLR 4.9.x, the JavaScript target generates EcmaScript 6 source code and must be transpiled to EcmaScript 5 ( Documentation for the JavaScript target recommends using WebPack and has instructions for using it.) The JavaScript runtime has a webpack.config.js to help out.使用 ANTLR 4.9.x,JavaScript 目标生成 EcmaScript 6 源代码并且必须转译为 EcmaScript 5( JavaScript 目标的文档建议使用 WebPack 并有使用说明。)JavaScript 运行时有一个 88311995388 运行时有一个 88311995388 运行时帮助 8831198647出去。 This is necessary for output that will run under an EcmaScript 5.x runtime.这对于将在 EcmaScript 5.x 运行时下运行的 output 是必需的。 ( class , let , etc. are all ES6 specific). classlet等都是 ES6 特定的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM