gpt4 book ai didi

node.js - 为什么我不能在 ES6 中 new 一个对象?

转载 作者:太空宇宙 更新时间:2023-11-04 02:56:32 25 4
gpt4 key购买 nike

我正在学习ES6,我编写了如下测试代码:

// export.js:
class Test {
constructor() {
console.log('teste5ty')
}
}

class Test2 {
constructor() {
console.log('test2')
}
}
export {Test, Test2}
export default Test

另一个导出文件代码如下:

// test2.js
class Teste3 {
construct() {
console.log('heheheheh')
}
}
export default Teste3

最后测试代码如下:

import Test from './export'
import {Test2} from './export'
import Teste3 from './test2'

new Test()
new Test2()
new Teste3()

通过 Babel 转换为 es5 后,我得到如下输出:

teste5ty
test2

显然,Test3没有实例化,为什么会出现这种情况?

最佳答案

我认为 Teste3 存在拼写错误 construct,而不是 constructor

关于node.js - 为什么我不能在 ES6 中 new 一个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43463123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com