Say, I have 2 constructors assigned to 2 variables:
var example1 = function(argument1){
this.argument1 = argument1;
}
var example2 = function(argument2){
this.argument2 = argument2;
}
And an array of objects containing objects from both of these constructors:
var array1 = new Array();
array1[0] = new example1(example);
array1[1] = new example2(example);
My question is, when I choose an item from the array, how can I print the name of the constructor variable it came from?
To make this clear and succint, here's an example:
console.log(array1[0].argument1)
Will print example. But I don't want that. I want it to print the name of the constructor variable it came from.
console.log(array1[0].constructor.toString());
Prints the content of the variable, but it is unsatisfactory.