search

Home  >  Q&A  >  body text

javascript - js attribute stack diagram

Above picture: obj stores the address, pointing to the object in the heap

So how is obj.a represented by a stack? It would be better to have a picture, thank you!

滿天的星座滿天的星座2751 days ago550

reply all(1)I'll reply

  • 黄舟

    黄舟2017-05-19 10:44:02

    In v8, using {a: 1}的时候, 会创建一个隐藏类, 有一个属性a, 类型为number, 偏移为0. 当通过obj.a获取这个类的实例的a属性时, 会通过obj查到堆中的起始地址, 加上偏移就可以获取到obj.a的地址了. 在古老的浏览器中, 一个object就是一个单纯的hash table, 和PHP is very similar.

    reply
    0
  • Cancelreply