Reputation: 13155
What is the type of CloseEvent.code
.
Is it an enum?
At the moment I have errorEvt.code === 1000
but I'd like something like errorEvt.code === Something.CLOSE_NORMAL
but what is Something?
Upvotes: 2
Views: 350
Reputation: 128796
These are pre-defined codes in the WebSocket Protocol (RFC 6455).
###7.4.1. Defined Status Codes
Endpoints MAY use the following pre-defined status codes when sending a Close frame.
####1000
1000 indicates a normal closure, meaning that the purpose for
which the connection was established has been fulfilled.
...
This Protocol doesn't define things like "CLOSE_NORMAL", the only references to things like that I can find are on MDN (which you've already linked) and as part of this Java implementation of the Websocket Protocol.
If you yourself want to reference these codes by their names, you can create this object yourself:
var Something = {
CLOSE_NORMAL: 1000,
...
}
This way you can simply reference the code through this Something object via Something.CLOSE_NORMAL
, etc.
Upvotes: 1