Discuss / JavaScript / 几个冗余和可以用相同方法的地方

几个冗余和可以用相同方法的地方

Topic source

app.js: wss.broadcast = function broadcast(data) { wss.clients.forEach(function(client) { client.send(data); }); };

function each(Client)  这个 each 可以省略掉

app.js function onConnect() { let user = this.user; let msg = createMessage('join', user, ${user.name} joined.); this.wss.broadcast(msg); // build user list: let users = this.wss.clients.map(function (client) { return client.user; }); //this.wss.broadcast(createMessage('list', user, users)); this.send(createMessage('list', user, users)); }

下面这2句是相等的 this.wss.broadcast(createMessage('list', user, users)); this.send(createMessage('list', user, users));


  • 1

Reply