Serialization functions for the complex datatypes - Node.js Data Type

Node.js examples for Data Type:Serialization

Description

Serialization functions for the complex datatypes

Demo Code


/**/*  ww  w.j  a va 2 s  .c  om*/
 *  Serialization functions for the complex datatypes. It reuses the
 *  other serialization functions to serialize the members of the object.
 */
Object.prototype.serialize = function()
{
    var result = '<struct>';

    for ( var member in this )
    {
        if ( typeof( this[ member ] ) != 'function' )
        {
            result += '<member>';
            result += '<name>' + member + '</name>';
            result += '<value>' + this[ member ].serialize() + '</value>';
            result += '</member>';
        }
    }

    result += '</struct>';
    return result;
}

Related Tutorials