I am currently working on a project that uses the following inheritance structure:
var Type = function(a){ this.a = a; }; var SubType = function(a){ Type.call(this, a); }; SubType.prototype = Object.create(Type.prototype); SubType.prototype.constructor = SubType;
Now I'm trying to add some pool of objects to the equation. The sample I'm currently using works something like (pseudocode):
Type.new = function(){ if object available in pool reset popped pool object return pool object else return new Type() } var a = Type.new();
Of course, the problem with using these two patterns is that the constructor calls SubType, which will not draw from the type pool. Is there any way around this without going to the factory structure? That is, there is a way, in the constructor, to do something line by line:
var SubType = function(){ build on top of instanceReturnedFromFunction() };
Knowing that this is not always consistent in different contexts, I would also like to preserve the inheritance structure, so that instanceof, etc. will work anyway:
source share