Best approach for creating an object from deserializing.
I'm looking for good approach when create object from serialized data. Let's assume that there is an object defined like that:
function A()
{}
A.prototype.a = "";
and serialized data: "a". So which approach will be better and why:
1. Create static method deserialize:
A.deserialize = function( data )
{
var a = new A();
a.a = data;
return a;
}
and will be called like that:
var a = A.deserialize("a");
2. Create method in prototype
A.prototype.deserialize = function ( data )
{
this.a = data;
}
and it will be called like that
var a = new A();
a.deserialize( "a" );
3. Process data in contstructor
function A(data)
{
this.a = data;
}
Consider that data can be different types for example - string, json or ArrayBuffer. I'm looking for a more generic solution. Is there any matter how I will create object?