1

I've been doing some research on the [[scope]] property of function object.[[scope]] should incorporate all the outer function's variable object in addition to global object.

Here, the innermost function which returns from the Inner function, should contain both Inner+Outer+Global variable object assigned to it's scope chain.But it only has Outer+Global variable objects assigned to it's scope chain.

Why Inner function is absent from the [[scope]] chain of the returned function which happens to be the immediate parent of returned function. Any suitable explanation for this behavior?

function Outer(){
   var a = 10
   return function Inner(){
     var b = 22
     console.log('ball')
     return function(){

        console.log(a+b)
     }

  }

}

var oppa = Outer()()
console.dir(oppa)

Result :

enter image description here

AL-zami
  • 8,902
  • 15
  • 71
  • 130
  • In my Chrome 61.0.3163.100 it does show all 3 closures (V8 6.1.534.41) – haim770 Sep 24 '17 at 20:16
  • Perhaps gets optimized away by the compiler. My Chrome shows the `Inner`. Could be there's a setting somewhere that controls optimizations for cod – llama Sep 24 '17 at 20:17
  • Did you expand the `Outer` closure? Does it have both variables? Try adding `a + 1` to `Inner` to see if that makes a difference. – llama Sep 24 '17 at 20:21
  • I just found that the question is marked duplicate. I checked the pinned question but can't relate it to my question. Can anyone summarize it to me in short ? – AL-zami Sep 24 '17 at 20:36

0 Answers0