I'm trying to extend one constructor with another, using prototype:
var objA = function(name){
var obj = this;
this.test.name = name;
window.setTimeout(function(){
console.log(obj.test.name)
}, 1)
}
var objB = function(name){
this.name = 'test'
}
objA.prototype.test = new objB();
var a = ['A', 'B', 'C', 'D']
for(var i = 0; i < a.length; i++){
new objA(a[i])
}
This approach works great for one object, but if ( as in this example ) i want to create multiple, it seems that the last entry ( 'D' ) overwrites previous, because in all 4 cases obj.test.name
returns D
. Maybe someone could point out what i'm doing wrong, or maybe other solution for this case. Thanks.