Skip to content

Commit e5f0cea

Browse files
EmmanuelDemeydarrachequesne
authored andcommittedNov 7, 2018
[docs] Use new JavaScript syntax inside the README (#3360)
1 parent 7e35f90 commit e5f0cea

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed
 

‎Readme.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ Any serializable data structures can be emitted, including:
5555
Sample code:
5656

5757
```js
58-
io.on('connection', function(socket){
59-
socket.emit('request', /* */); // emit an event to the socket
60-
io.emit('broadcast', /* */); // emit an event to all connected sockets
61-
socket.on('reply', function(){ /* */ }); // listen to the event
58+
io.on('connection', socket => {
59+
socket.emit('request', /* */); // emit an event to the socket
60+
io.emit('broadcast', /* */); // emit an event to all connected sockets
61+
socket.on('reply', () => { /* */ }); // listen to the event
6262
});
6363
```
6464

@@ -84,7 +84,7 @@ This is a useful feature to send notifications to a group of users, or to a give
8484
## Installation
8585

8686
```bash
87-
npm install socket.io --save
87+
npm install socket.io
8888
```
8989

9090
## How to use
@@ -93,20 +93,20 @@ The following example attaches socket.io to a plain Node.JS
9393
HTTP server listening on port `3000`.
9494

9595
```js
96-
var server = require('http').createServer();
97-
var io = require('socket.io')(server);
98-
io.on('connection', function(client){
99-
client.on('event', function(data){});
100-
client.on('disconnect', function(){});
96+
const server = require('http').createServer();
97+
const io = require('socket.io')(server);
98+
io.on('connection', client => {
99+
client.on('event', data => { /**/ });
100+
client.on('disconnect', () => { /**/ });
101101
});
102102
server.listen(3000);
103103
```
104104

105105
### Standalone
106106

107107
```js
108-
var io = require('socket.io')();
109-
io.on('connection', function(client){});
108+
const io = require('socket.io')();
109+
io.on('connection', client => { ... });
110110
io.listen(3000);
111111
```
112112

@@ -118,10 +118,10 @@ to pass the `Server` to `socket.io`, and not the express application
118118
function. Also make sure to call `.listen` on the `server`, not the `app`.
119119

120120
```js
121-
var app = require('express')();
122-
var server = require('http').createServer(app);
123-
var io = require('socket.io')(server);
124-
io.on('connection', function(){ /**/ });
121+
const app = require('express')();
122+
const server = require('http').createServer(app);
123+
const io = require('socket.io')(server);
124+
io.on('connection', () => { /**/ });
125125
server.listen(3000);
126126
```
127127

@@ -131,10 +131,10 @@ Like Express.JS, Koa works by exposing an application as a request
131131
handler function, but only by calling the `callback` method.
132132

133133
```js
134-
var app = require('koa')();
135-
var server = require('http').createServer(app.callback());
136-
var io = require('socket.io')(server);
137-
io.on('connection', function(){ /**/ });
134+
const app = require('koa')();
135+
const server = require('http').createServer(app.callback());
136+
const io = require('socket.io')(server);
137+
io.on('connection', () => { /**/ });
138138
server.listen(3000);
139139
```
140140

0 commit comments

Comments
 (0)
Please sign in to comment.