Easy accesses to members higher up in object hierarchy

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Xillez
    New Member
    • Jul 2013
    • 93

    Easy accesses to members higher up in object hierarchy

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

    Code:
    let obj = {
      instance_id: "<some uuid>"
      child1:
      {
        child2:
        {
          function log() => console.log(instance_id);
        }
      }
    }
    Is there some clever way of allowing "instance_i d" 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.
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Is there some clever way of allowing "instance_i d" 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,
    Code:
    var obj = { var1 : "value"};
    obj.var2 = obj.var1;

    Comment

    Working...