JavaScript access parent object attribute

前端 未结 6 1871
臣服心动
臣服心动 2020-12-31 17:16

I have a small issue in JS, I have two nested objects, and I would like to access a variable from the parent, like so:

var parent = {
    a : 5,

    child:          


        
6条回答
  •  悲&欢浪女
    2020-12-31 17:51

    I think it doesn't really make sence to do it like that since you can access child object only through its parent. so why add a mthod displayB to the child while you can add it to the parent which has access to all child properties.

提交回复
热议问题