transform-b​​uiltin-extend似乎不起作用

时间:2016-09-18 10:05:16

标签: javascript ecmascript-6 babeljs es6-class

我在运行的课程中遇到错误:

ArrayList list= new ArrayList();
list=  getIntent().getStringArrayListExtra("list");

我的.babelrc:

Uncaught TypeError: Failed to construct 'FormData': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

at Form.ExtendableBuiltin (http://local.yandex.ru:30002/bundle.js:79395:14)
at new Form (http://local.yandex.ru:30002/bundle.js:79422:103)

我的课程:

{
    "presets": ["react", "latest"],
    "plugins": [
        "babel-plugin-syntax-decorators",
        "babel-plugin-transform-decorators-legacy",
        ["babel-plugin-transform-builtin-extend", { // Class Extending Natives
            globals: ["FormData"],
            approximate: true
        }],
        "transform-es2015-arrow-functions",
        // "syntax-async-functions",
        // "transform-async-to-generator",
        // "transform-regenerator",
        "transform-object-rest-spread",
        "transform-rebem-jsx",
        "transform-es2015-typeof-symbol"
    ],
}

一段已编译的代码:

import map from 'lodash/map'

export default class Form extends FormData {
    constructor (data) {
        super()
        map(data, (val, key) => this.append(key, val))
    }
}

function _extendableBuiltin(cls) { function ExtendableBuiltin() { cls.apply(this, arguments); } cls

期待这样的事情:

FormData
巴贝尔 - 版本 6.14.0(babel-core 6.14.0)

webpack --version 版本:webpack 1.13.2

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您必须将approximate选项设置为false。来自the plugin GitHub repository

  

在不支持重新分配现有对象原型的旧浏览器上,您需要启用近似模式,这将回退到使用简单ES5继承到approximate扩展类的Babel 5行为,虽然您的结果可能会因您的目标而异。