Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
73
rated 0 times [  77] [ 4]  / answers: 1 / hits: 34170  / 13 Years ago, sun, march 27, 2011, 12:00:00

For example I have such an object:



var a = {
'light': 'good',
'dark' : {
'black': 'bad',
'gray' : 'not so bad'
}
}


and such a code:



var test = function(obj) {
// do smth with object
// I need to get obj's name ('dark' in my way)
}
test(a.dark);


How to get name of object in function's body. So I mean I should know that obj's name is 'dark'.



I've tried inspect object with firebug, but it's only show object's property. It's not showing some internal methods or properties, with which I'll be able to know



Thank you.


More From » object

 Answers
0

You can't. You're only passing the object { black : 'bad', gray : 'not so bad' } into test. This object does not intrinsically have the name dark, it's just an object that happened to exist as the property dark of the object a. This information is irretrievably lost when passing it into a function.



You're basically trying to retrieve the variable name that held the value before the value got passed into the function. That's not possible.


[#93058] Thursday, March 24, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daphnew

Total Points: 716
Total Questions: 113
Total Answers: 113

Location: Bonaire
Member since Sat, May 1, 2021
3 Years ago
;