0

I have the following object:

var process = {
    template1: {
        ref: // here I want to get 'template1'
    }
}

How can I access the parent key name as above?

Inigo
  • 8,110
  • 18
  • 62
  • 110
  • If I understand you'd have to declare the object first, then do `process.template1.ref = process.template1` – elclanrs Sep 12 '14 at 21:53
  • Please provide more information. Do you want to create a self reference? – Felix Kling Sep 12 '14 at 21:57
  • `ref: function() { alert('my parent is ' + this); }` –  Sep 12 '14 at 22:13
  • question: why? What problem are you trying to address that requires the template1 ref knows its owner? – Mike 'Pomax' Kamermans Sep 12 '14 at 22:24
  • Thanks to those linking to duplicate question which I missed. Long story, Mike, but I have a structure similar to [this answer](http://stackoverflow.com/a/17923310/521392). As you can see, sometimes there is good reason to want to know the parent. Torazaburo, 'this' returns the entire object, not the name (string) which is what I wanted. – Inigo Sep 13 '14 at 12:16

0 Answers0