Any naming conventions regarding custom properties on NodeJS socket object

26 views
Skip to first unread message

Zhongcai Ng

unread,
Mar 23, 2015, 11:20:12 PM3/23/15
to nod...@googlegroups.com

Am tagging custom properties on NodeJS socket objects. ie, socket.id, socket.someCustomProperty, etc.

Like to ask if there's any prohibition imposed on custom property names. Am scared that I will break something unintentionally. With current and future versions of NodeJS

Aria Stewart

unread,
Mar 23, 2015, 11:30:33 PM3/23/15
to nod...@googlegroups.com
On Monday, March 23, 2015 at 11:20:12 PM UTC-4, Zhongcai Ng wrote:

Am tagging custom properties on NodeJS socket objects. ie, socket.id, socket.someCustomProperty, etc.

Like to ask if there's any prohibition imposed on custom property names. Am scared that I will break something unintentionally. With current and future versions of NodeJS

That's tough. It's a wide open namespace, and predicting the future is impossible.

If you can use ES6 features, consider not putting the property on the object, but instead using a WeakMap, and keeping your own stuff separate:

    var wm = new WeakMap();
    wm.set(socket, { yourproperty: value });

    wm.get(socket).yourproperty

If not, namespace hard. Perhaps socket.yourmodulename.yourproperty? socket['yourmodulename:yourproperty']?

Aria

Fedor Indutny

unread,
Mar 23, 2015, 11:53:52 PM3/23/15
to nod...@googlegroups.com
I guess the important question to ask is: do you really need it in a first place? Is it possible to wrap the net.Socket into some other object on your application level, and set the properties on it instead?
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/9958558a-a4ea-4344-a498-90fe801db4d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages