Lets say I have
var myObject = {
'myFunction' : function () {
// something here that lets me get 'myObject'
}
}
I have tried various functions found here and stuff like this.constructor.name but i always get 'Object' as the value returned. Is there any way to get the actual name of the variable in this situation?
edit to explain the why so maybe people will better understand...I want to be able to make a function that is continuously called with setInterval. Something like this:
var myObject = {
'intval' : '',
'timeout' : 500,
'start' : function () {
this.objectName = 'myObject'; // <--I want this to be dynamically popped
this.intval=window.setInterval("window['"+this.objectName+"'].myFunction()",this.timeout);
},
'stop' : function () {
window.clearInterval(this.intval);
this.intval='';
},
'myFunction' : function () {
// do something
}
}
This works just fine if i hardcode 'myObject' to this.objectName but I don't want it to be hardcoded. Problem is that I wan't just do setInterval("window[this.objectName]",100) becausethisis not in the right context whensetInterval` is run, and I don't want to have the objectname hardcoded