I've finally found a satisfactory way to create classes on JavaScript. Are there any cons to it? Depending on external OO libraries is really bad, using prototypes/new has some limitations, using only hashes has others. Dealing with classes was always a pain in JavaScript and it didn't help that every library has it's own way to deal with ti. But since some time I've finally "set" with this design:

function my_class(extend,init){
    var self = extend || {};

    var private = 5;
    self.public = 5;
    self.get_private = function(){
        return private;
    };

    for (var key in init) self[key] = init[key];
    return self;
};


Tests:

var instance = my_class();

// publics and privates
console.log(instance.public);
console.log(instance.get_private());

// methods never lose context
(function(method){
    console.log(method());
})(instance.get_private);

// multiple inheritance trivial
var random_obj = {a:1,b:2,c:3};
my_class(random_obj); // now random_obj inherits my_class

// serializable, store in a DB and recover it with:
var serialized = JSON.stringify(instance);
var instance = my_class({},JSON.parse(serialized));
console.log("Instance: ",instance);


I'm surprised how this simple design solves all the problems of the other approaches. Prototypes make multiple inheritance hard, hashes won't allow privates, there's no more the "this" binding issue, instances are JSON-serializable, all that without depending on external libraries. Is there any cons to this method, or something that is hard to do with it - or can I just go and start preaching about it?
What about regular inheritance? Is extend supposed to be the superclass?

foo = { foo: "bar" };

a = my_class(foo);
b = my_class(foo);

a.foo = "baz";
console.log(b.foo);

--&gt; "baz";


I would expect a and b to have their own state, yet they share a single foo property.