比如我需要将 Gift.js 文件的内容,被 index.js 引入
- Gift.js
function Gift() {
}
Gift.prototype = {
init(socket,io) {
console.log('init run');
console.log(`socket`, socket);
node
socket.on('chat room message', msg => { // 发送给某个房间
console.log(msg);
io.emit('chat room receive' + msg.roomNum, msg)
});
socket.on('sendgift', msg => {
// 发送给某个房间
io.emit('recvgift' + msg.roomNum, msg)
});
}
}
module.exports = Gift;
- Index.js
const Gift = require('./mobile/Gift');
...
let gift = new Gift();
gift.init(socket,io);
...
网友评论