serialize
Serializes an object to a value that can be passed to JSON.stringify.
serialize(obj)
Recursively serializes a map-like or list-like object.
import canReflect from "can-reflect";
canReflect.serialize({foo: "bar"}) //-> {foo: "bar"}
It does this by recursively:
- Checking if
obj
is a primitive, if it is, returns the value. - If
obj
is an object:- calling the
@can.serialize
property on the value if it exists. - If the
@can.serialize
value doesn't exist, walks through every key-value onobj
and copy to a new object.
- calling the
Parameters
- obj
{Object}
:A map-like or array-like object.
Returns
{Object}
:
Returns a plain object or array.