JSFiddle - React, Tailwind, and code Playground

JavaScript

function Person( name, sex, age ) {
    this.name = name;
    this.sex = sex; 
    this.age = age;
}

Person.prototype.serialize = function () {
    var obj = this; 
    return '{ ' + Object.getOwnPropertyNames( this ).map( function ( key ) {
        var value = obj[key];
        if ( typeof value === 'string' ) { value = '"' + value + '"'; }
        return '"' + key + '": ' + value;
    }).join( ', ' ) + ' }'; 
};

Person.deserialize = function ( input ) {
    var obj = JSON.parse( input );
    return new Person( obj.name, obj.sex, obj.age );
};

var person = new Person( 'John', 'male', 25 );
var string = person.serialize();
console.log( string );

var person2 = Person.deserialize( string );
console.log( person2 );
console.log( person2 instanceof Person );