199
rated 0 times
[
200]
[
1]
/ answers: 1 / hits: 16990
/ 7 Years ago, sat, march 18, 2017, 12:00:00
I am creating a JavaScript code and I had a situation where I want to read the object name (string) in the object method. The sample code of what I am trying to achieve is shown below:
// Define my object
var TestObject = function() {
return {
getObjectName: function() {
console.log( /* Get the Object instance name */ );
}
};
}
// create instance
var a1 = TestObject();
var a2 = TestObject();
a1.getObjectName(); // Here I want to get the string name a1;
a2.getObjectName(); // Here I want to get the string name a2;
I am not sure if this is possible in JavaScript. But in case it is, I would love to hear from you guys how to achieve this.
More From » javascript