I'm studying the WebRTC tutorial from Google's codelab.
In its index.js section for Node.js. I has the following line.
var fileServer = new(nodeStatic.Server)();
I understand new is an operator to create instances. But it above is using new(nodeStatic.Server)() which confuses me.
Can someone please explain it for me? Thanks.
nodeStatic.Server is apparently a constructor. So, your code works like this;
let serverConstructor = nodeStatic.Server;
let fileServer = new serverConstructor();
The parens are used in your original code to make the competing precedence between new, () and the . operator a little more obvious. You'd have to study the precedence rules in the Javascript spec to see if the parens around nodeStatic.Server are actually needed or not (it appears they are not, but it takes some detailed knowledge of the spec or running your own tests to know that).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With