Namespaces and Serialization

● ARCHIVED · READ-ONLY
Started by Kaelan 1 posts View original ↗
  1. Up to now, I've been using this syntax to contain my classes inside namespaces:
    PHP:
    var Namespace = Namespace || {};
    
    Namespace.Class = function(...arguments) {
        this.initialize(...arguments);
    };
    
    Namespace.Class.prototype.initialize = function() {
        // code
    };

    And it's worked. But whenever an object defined this way needs to be serialized (i.e. say you put an instance of it inside Game_Battler), as soon as its loaded it loses its type information and becomes a plain Object.

    This doesn't happen if I declare the object normally, outside of a namespace:
    PHP:
    function Class(...arguments) {
        this.initialize(...arguments);
    };
    
    Class.prototype.initialize = function() {
        // code
    };

    In that case, it works normally and serialization preserves the type and methods.

    I'm guessing this has something to do with how MV's JsonEx serializes object information. Does anyone know how to get this to work with classes inside namespaces?