N
N
Nikolai Chuprik2018-02-11 17:56:45
JavaScript
Nikolai Chuprik, 2018-02-11 17:56:45

How to access the context inside an anonymous function in such a situation?

var outerObj = {
  x: 10,
  innerObj: { y: 20}
}
 
outerObj.innerObj.f = function() {
    console.log (this.y);       // 20 — это понятно
    //  А вот как получить в этом месте доступ к 'x', не передавая его в виде аргумента функции?
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
string15, 2018-02-11
@string15

outerObj.innerObj.f.bind(outerObj)()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question