W
W
websiller2017-09-12 22:31:23
JavaScript
websiller, 2017-09-12 22:31:23

How to reference external js object from internal?

var out = {
   in:{
      f:function() {
        //Здесь нужно получить ссылку на объект out а не in
      }
   }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SOmni, 2017-09-13
@websiller

This cannot be done without additional steps. If you really want parent, then you can do this:

var out = {
    name: "OUT",
    in: {
        name: "IN",
        f: function() {
            console.log('in.name =', this.name);
            console.log('in.parent.name =', this.parent.name);
        }
    },
    init: function() {
        this.in.parent = this;
        return this;
    }
}.init();

out.in.f();

https://jsfiddle.net/q243knuu

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question