简体   繁体   English

Socket.io - 使用多个 function arguments 不好的做法?

[英]Socket.io - is using multiple function arguments bad practice?

I'm new to socket.io and have noticed that in general when multiple parameters need to be sent, they are sent in a single object.我是 socket.io 的新手,注意到通常需要发送多个参数时,它们会在单个 object 中发送。 ( socket.emit('message name', {arg1: ..., arg2: ...}) ) ( socket.emit('message name', {arg1: ..., arg2: ...}) )

However, I have also noticed that passing multiple arguments in the function appears to work.但是,我也注意到在 function 中传递多个 arguments 似乎有效。 ( socket.emit('message name', arg1, arg2) ) ( socket.emit('message name', arg1, arg2) )

Is there any disadvantage of emitting messages with multiple arguments?使用多个 arguments 发出消息有什么缺点吗?

There is no disadvantage to using either option.使用任何一个选项都没有缺点。 It's just a matter of preference.这只是一个偏好问题。 Both are supported in the Socket.io documentation Socket.io 文档支持两者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM