Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there other way to reference grandParent object in javascript

Tags:

javascript

I have following code:

var objectParent:{
     child1:{
       test1:function(){},
       test2:function(){}
      },

      child2:{
       demo1:function(){},
       demo2:function(){},
       parent:this  // gives child2
       grandparent: .... // need to reference objectParent here

      }

    }

We can reference object by using this keyword, But what for grand object or i mean parent of parent object?

Now, i am using grandparent:objectParent to reference parent object

Is there other way like this selector to reference parentObject?

Are these my coding is bad,good or better?

like image 897
blue ghhgdtt Avatar asked Jan 14 '23 03:01

blue ghhgdtt


1 Answers

If all your objects have a parent property that refers to their parent, then can get the grandparent with object.parent.parent.

like image 116
Barmar Avatar answered Jan 16 '23 22:01

Barmar