468,490 Members | 2,598 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,490 developers. It's quick & easy.

Easy accesses to members higher up in object hierarchy

90 64KB
Language is TypeScript (didn't have a specific category).
Say I have a object hierarchy like so:

Expand|Select|Wrap|Line Numbers
  1. let obj = {
  2.   instance_id: "<some uuid>"
  3.   child1:
  4.   {
  5.     child2:
  6.     {
  7.       function log() => console.log(instance_id);
  8.     }
  9.   }
  10. }
  11.  
Is there some clever way of allowing "instance_id" to be accessible to the lower objects without passing them through functions down the hierarchy and such?

Cant store as static (objects are from classes) due to multiple instances of this object.

Would really appreciate some ideas on this. Thanks in advance.
Dec 10 '20 #1
1 2115
dev7060
430 Expert 256MB
Is there some clever way of allowing "instance_id" to be accessible to the lower objects without passing them through functions down the hierarchy and such?

Cant store as static (objects are from classes) due to multiple instances of this object.
I don't use typescript. How about in two steps when the outer object is defined so no undefined is returned. In vanilla js,
Expand|Select|Wrap|Line Numbers
  1. var obj = { var1 : "value"};
  2. obj.var2 = obj.var1;
Dec 13 '20 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Erik Johnson | last post: by
reply views Thread by archway | last post: by
100 posts views Thread by E. Robert Tisdale | last post: by
4 posts views Thread by Dave Veeneman | last post: by
2 posts views Thread by tinman | last post: by
1 post views Thread by tinman | last post: by
9 posts views Thread by Tom Plunket | last post: by
1 post views Thread by Jay Pondy | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.