Say I have a situation like this:
const foo = {
bar: {
star: {
guitar: 'geetar'
}
}
}
and then I have:
const stew = {
moo: () => foo.bar.star.guitar
}
then I call moo in the next tick of the event loop:
process.nextTick(function(){
const guitar = stew.moo();
});
my question is - is there any way/trick to get the string representation of the path: "foo.bar.star.guitar"?
I could replace the code with a string:
const stew = {
moo: () => 'foo.bar.star.guitar'
}
but I am looking to find a way to get a string representation. One important detail is that I want to generate a useful error message - if someone puts in an object path that doesn't exist. That is the whole purpose of getting a string representation - for a useful error message.