Having sent a moderately complex object (an array with each element an array of objects from mysqli_fetch_object($rs) or an empty array ) I have found that when iterrating over the objects in JS with "for (x in y)" they have the property toJSON. Is this normal? If so, is there some way to get rid of these properties, or are they required for re-serialisation? If the latter, is it be possible to declare that one has no interest in reserialising the returned object to avoid the extra property?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The toJSON property is added to the prototypes of the various types that are JSON-encodable in the jsolait library, which is why you are seeing them on the JSON-decoded objects. Is it possible to just ignore them, or is there some reason that you need to access each property of each item?
Yours,
Craig
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't need to strictly, but it's often convenient to iterate over the properties of an object. I guess I could use typeof() to skip functions, or perhaps even figure out a way to determine that it's a prototype function (I forget exactly how the inheritance-like chain of prototypes thing works in JS). Still, it'd be nice to have a function to call to get just the values, or a parameter to the call that would prevent the toJSON function from being added.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Having sent a moderately complex object (an array with each element an array of objects from mysqli_fetch_object($rs) or an empty array ) I have found that when iterrating over the objects in JS with "for (x in y)" they have the property toJSON. Is this normal? If so, is there some way to get rid of these properties, or are they required for re-serialisation? If the latter, is it be possible to declare that one has no interest in reserialising the returned object to avoid the extra property?
The toJSON property is added to the prototypes of the various types that are JSON-encodable in the jsolait library, which is why you are seeing them on the JSON-decoded objects. Is it possible to just ignore them, or is there some reason that you need to access each property of each item?
Yours,
Craig
I don't need to strictly, but it's often convenient to iterate over the properties of an object. I guess I could use typeof() to skip functions, or perhaps even figure out a way to determine that it's a prototype function (I forget exactly how the inheritance-like chain of prototypes thing works in JS). Still, it'd be nice to have a function to call to get just the values, or a parameter to the call that would prevent the toJSON function from being added.