I am using the latest versions of node.js and socket.io. At the same time, the application starts in strict mode, since throughout it uses the syntax class expressions.

When connecting a socket, the application crashes:

TypeError: Cannot set property request of #<Socket> which has only a getter 

I read on the githaba that if you comment out the line (node_modules\socket.io\lib\socket.js:63:16) then everything will be ok, and that this will in no way affect the operation of the application.

Actually I want to ask you what the line this.request = client.request; and where / at what point it is used. And really, if you comment it out, it will not affect the operation of the application?

 function Socket(nsp, client){ //..more properties this.request = client.request; //..more properties } 

    1 answer 1

    what is the line this.request = client.request;

    This line is not needed, because it does nothing.

    And really, if you comment it out, it will not affect the operation of the application?

    Yes it is. Outside of strict mode, an attempt to change an immutable property is ignored by default.

     var socket = { get request() { return 0; } }; socket.request = 1; console.log(socket.request); // 0 

    In strict mode, this results in an error:

    Uncaught TypeError: Cannot set property request of #<Object> which has only a getter (...)

    • And if "This line is not needed, because it does not do anything.", Why did they put it into the module at all? And why does the method itself need a function socket (nsp, client)? - sanu0074
    • one
      @ sanu0074 This question is better to ask the author of the module. I can not say what he wanted when he wrote this code. - Peter Olson