【问题标题】:Babel transpiled code does not support static methods in IE11Babel 转译代码不支持 IE11 中的静态方法
【发布时间】:2015-12-09 15:48:48
【问题描述】:

Babel 转译的 js 工作正常,但在 IE11 上静态继承似乎不起作用。有什么想法吗?

class SuperClass {
    constructor () {}

    static test () {}
}

class Sub extends SuperClass {
    constructor () {
        super();
    }
}

Sub.test(); //Results in: "Object doesn't support property or method 'test'

【问题讨论】:

    标签: internet-explorer-11 ecmascript-6 babeljs


    【解决方案1】:

    好像Babel没有处理这种情况,其实在inherits这个helper中,如果Object.setPrototypeOf方法是undefined,Babel只是简单的把超类附加到__proto__键上。

    我已经解决了这个问题,包括这个polyfill/workaround。目前,它似乎工作正常,直到 Babel 团队不会修复此行为。

    【讨论】:

    • 有趣的是 setPrototypeOf 是 es2015 的一个特性:)。
    • 这解决了我在 IE10 中使用 React 应用程序的类似问题。谢谢!
    猜你喜欢
    • 2018-08-20
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 2016-05-03
    相关资源
    最近更新 更多