Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 构造函数中的babeljs类静态_Javascript_Babel 6 - Fatal编程技术网

Javascript 构造函数中的babeljs类静态

Javascript 构造函数中的babeljs类静态,javascript,babel-6,Javascript,Babel 6,问题是在调用super方法之前,如何从构造函数中访问类静态属性 class A { constructor(input) { console.log('A', typeof new.target); } } class B extends A { static template = ''; constructor() { console.log('B', typeof new.target); super();

问题是在调用super方法之前,如何从构造函数中访问类静态属性

class A
{
    constructor(input) {
        console.log('A', typeof new.target);
    }
}

class B extends A
{
    static template = '';

    constructor() {
        console.log('B', typeof new.target);
        super();
    }
}

class C extends B
{
    static template = 'CCC';
}

new C();
出于某种原因,我得到:

B undefined
A undefined
而不是

B function
A function
我大约一年前就有了。目前,它提供的解决方案不再可行


您可以在中尝试该代码。有趣的是,这段代码在没有babel的情况下运行良好(例如,在最新的Chrome中),并且当es2015复选框关闭时。

这似乎是babel中的一个bug。我写了一个小插件,可以传输新的文件。target:


这只表明存在Babel bug,而不是
new.target
无法正常工作。您应该报告说,
new.target
不再传输,暂时使用旧的巴别塔版本。
$ npm install --save-dev git://github.com/vbarbarosh/babel_plugin_transform_es2015_newtarget
$ cat .babelrc
...
    "plugins": ["transform-es2015-newtarget"],
...