Sencha Cmd, C2001 closure compiler error: extending native class: Array

Sencha Cmd, C2001 closure compiler error: extending native class: Array

当运行 Sencha Cmd v6.5.3.6 时,我收到以下错误信息:

[ERR] C2001: Closure Compiler Error (This code cannot be converted from ES6. extending native class: Array) -- compression-input:111263

错误是由这段代码引起的:

class Chains extends Array {
}

class 声明中的方法仍然出现错误。

有没有办法让 Sencha Cmd 编译这段代码?

更新: 为了解决问题,我将代码更改为:

function Chains() { };
Chains.prototype = new Array;
Chains.prototype.anyMethod = function () { }

我认为 ExtJS 目前不支持该语法。目前,您可能不得不使用他们的语法:

Ext.define('Chains', {
    extend: 'Array'
});

然后在你的代码中你可以这样调用它:

var chns = Ext.create('Chains');
chns.push('a');
console.log(chns);

您正在使用 ES6 的一项功能that cannot be transpiled into pre-ES6 code

默认情况下,Sencha Cmd 将您的代码转换为 ES6 之前的代码,因为尚未取消对 IE11 的支持。

您可以从 Sencha Cmd 6.5.0 开始禁用代码转译,如所述in the official docs:

There are cases where you won't need all that transpiling. Maybe you’re targeting Electron or you only support modern browsers that have all these features. You can disable the transpiler and still use the Sencha Cmd code compressor against your native ES6 code. Just a tweak to the app.json file and say goodbye to the transpiler and its polyfills:

"output": {
    "js": {
        "version": "ES6"
    }
}