Home  >  Q&A  >  body text

javascript - How to access the properties of the outer object in js

        {
          pName: 'MapType',
          defaultType: 0,
          events: {
            init(o) {
              console.log(this.pName)
            }
          }
        }

As shown above, how can I get this.pName correctly

世界只因有你世界只因有你2711 days ago406

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-19 10:40:10

    var obj = {
        pName: 'MapType',
        defaultType: 0,
        events: {
            init(o) {
                console.log(this.pName)
            }
        }
    };
    
    obj.events.init.call(obj);

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:40:10

    var obj = {
        pName: 'MapType',
        defaultType: 0,
        events: {
            init(o) {
                console.log(obj.pName)
            }
        }
    }
    obj.events.init();

    reply
    0
  • Cancelreply