小编Kat*_*ine的帖子

Babel 7:Function.prototype.toString:“此”不是Function对象

我想创建应该在ie11上运行的Web组件。我正在用gulp(和gulp-babel,其中包括babel 7)编译js。

到目前为止,当我使用Babel进行编译时,它可以在Chrome中运行,但是会在ie11:中发送错误Function.prototype.toString: 'this' is not a Function object

在gulpfile.js中,我有这个:

.pipe(babel({
    "presets": [
        ["@babel/preset-env", {
            "targets": {
                "browsers": [
                    "Chrome >= 52",
                    "FireFox >= 44",
                    "Safari >= 7",
                    "Explorer 11",
                    "last 4 Edge versions"
                ]
            }
        }]
    ]
}))
Run Code Online (Sandbox Code Playgroud)

在js中,我有类似这样的内容(我在网上找到了用于测试的示例代码):

class MyCustomTag extends HTMLElement {
    connectedCallback() {
        this.innerHTML = '<h2>My custom element</h2><button>click me</button>';
        this.style.backgroundColor = 'blue';
        this.style.padding = '20 px';
        this.style.display = 'inline-block';
        this.style.color = 'white';
    }
}

try {
    customElements.define('my-custom-tag', MyCustomTag)
} catch (err) {
    const h3 …
Run Code Online (Sandbox Code Playgroud)

javascript babel web-component gulp gulp-babel

3
推荐指数
1
解决办法
1870
查看次数

标签 统计

babel ×1

gulp ×1

gulp-babel ×1

javascript ×1

web-component ×1