I may have worded the title badly but I figure the best way to explain what I'm trying to do is to show an example...
So consider the following code:
var obj={}
Object.defineProperty(obj, "a", { get: function() { return 1 }, enumerable:true, configurable:true } )
Object.defineProperty(obj, "b", { get: function() { return 2 }, enumerable:true, configurable:true } )
Object.defineProperty(obj, "c", { get: function() { return 3 }, enumerable:true, configurable:true } )
var codeString="return obj.a + obj.b + obj.c"
var func=Function(codeString)
func()//6
I have an object with get properties and a function made from a string. What I would like to be able to do is when the function is run (func()
) and specific get properties in the function are called i'd like to know the index in the string (codeString
) where it is called from. Which I can use / report on in the get function.
So for example, when property b is called in obj obj.b
in the function that would be, index is say, 19..
I'm not sure if this is possible and couldn't think of a way of doing this so thought I'd put it out there..
If this doesn't make sense then please say and I'll try to explain it better.. Thanks for any help you may have...