Javascript 为什么es6中需要构造函数?
为什么我在测试id中编写“new ServerNotificationApi”时不调用构造函数,对我来说Javascript 为什么es6中需要构造函数?,javascript,unit-testing,ecmascript-6,enzyme,Javascript,Unit Testing,Ecmascript 6,Enzyme,为什么我在测试id中编写“new ServerNotificationApi”时不调用构造函数,对我来说new ServerNotificationApi.constructor()可以工作,但我不理解为什么我在编写new ServerNotificationApi时在单元测试“TypeError:\u serverNotifications.default不是构造函数”时出错 阶级 试验 导出的是类的实例,而不是类本身。你基本上在做: let foo = new ServerNotificat
new ServerNotificationApi.constructor()
可以工作,但我不理解为什么我在编写new ServerNotificationApi
时在单元测试“TypeError:\u serverNotifications.default不是构造函数”时出错
阶级
试验
导出的是类的实例,而不是类本身。你基本上在做:
let foo = new ServerNotificationApi();
new foo();
这,是的,不起作用。清除导出
中的新
导出的是类的实例,而不是类本身。你基本上在做:
let foo = new ServerNotificationApi();
new foo();
这,是的,不起作用。清除导出
中的新
export default new ServerNotificationApi()
↑↑↑
let foo = new ServerNotificationApi();
new foo();