I’m writing a node application and I would like to get the name of the variable that invokes a constructor.
a=new constructorFunction();
b=new constructorFunction();
function constructorFunction(){
this.test="it works!";
this.doSomething=function(){
//this should return the contents of this.test
}
}
console.log(a.doSomething());
console.log(b.doSomething());
As the comment says, I’d like to return the values of a.test and b.test. How can I accomplish this?
It doesn’t need to be any more complicated than this (fiddle):