Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么es6中需要构造函数?_Javascript_Unit Testing_Ecmascript 6_Enzyme - Fatal编程技术网

Javascript 为什么es6中需要构造函数?

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

为什么我在测试id中编写“new ServerNotificationApi”时不调用构造函数,对我来说
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();