Say I have
var myObject = { 'myFunction' : function () {
I tried various functions found here and things like this.constructor.name
, but I always get "Object" as the return value. Is there a way to get the actual variable name in this situation?
change to explain why, maybe people will understand better ... I want to be able to make a function that is constantly called with setInterval. Something like that:
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 fine if I hardcode 'myObject' to this.objectName, but I don't want it to be hard coded. The problem is that I just did not execute setInterval("window[this.objectName]",100) because
this is not in the right context when
setInterval`, and I do not want to have a hardcoded object name
source share