Add option to exclude function properties when encoding objects#78
Add option to exclude function properties when encoding objects#78brentd wants to merge 1 commit intokawanet:masterfrom
Conversation
This matches the behavior of JSON.stringify
|
Closing since there doesn't seem to be any interest. |
|
I'm sorry to the late response. I was pretty busy for those months. Issue #71 wants to map undefined to be stripped. PR #78 wants to map function to null. Those two seem similar requests. Your code looks pretty clean. LGTM. The option parameter name
I like the new default behavior given with your patch. var obj = { f: function(){} }
msgpack.decode(msgpack.encode(obj)) // {}Idea:
I'm more happy when you could also give a code and README for those two! |
|
Sorry @kawanet, I hope I didn't make you feel guilty - I know how it goes. I was just cleaning out my PR queue. Thanks very much for the feedback. I'll do what I can to address your comments. |
The behavior of
JSON.stringifyis to exclude properties on an object that store a function:Current behavior of
msgpack-lite:Behavior this PR introduces - excluding functions is the new default:
Justification
The behavior of JSON is convenient for me, because when prototyping ideas, I often serialize whole ES6 class instances without explicitly picking properties (I'm lazy).
msgpack-litealready excludes the class prototype's functions since it usesObject.keysto encode objects, but functions set as properties on the object (like functions that are bound using the common idiom in the constructor) will remain.boundFuncwould be sent over the wire asnulland is of no benefit.That said, I realize someone out there might have actually added a custom encoder for functions, so excluding them by default is maybe not the right solution. 100% open to discussing and making any adjustments necessary.
An alternative idea may be a codec option which allows you to exclude certain types from serialization.