function Channel(name) { this.name = name this.userlist = [] this.join = function(user) { let channel = this this.userlist.push(user) this.userlist.forEach(function(item) { item.sendRaw(`:${user.nickname} JOIN ${channel.name}`) }) } this.part = function(user) { let channel = this let userIndex = this.userlist.indexOf(user) if (userIndex >= 0) { this.userlist.forEach(function(item) { item.sendRaw(`:${user.nickname} PART ${channel.name}`) }) this.userlist.splice(index, 1) } } this.sendMsg = function(from, message) { const channel = this this.userlist.forEach(function(item) { item.sendMsg(from, message, channel.name) }) } } module.exports = Channel