Shallow & Deep Binding - What will this program do?

I'm not sure how to do this ...

function f1() { var x = 10; function f2(fx) { var x; x = 6; fx(); }; function f3() { print x; }; f2(f3); }; 

For each of the following two binding methods, what will the program print? A) Shallow snapping B) Deep snapping

Thanks for the help!

+5
source share
2 answers

Deep / shallow binding only makes sense when a procedure can be passed as an argument to a function.

  • A deep binding binds the environment during the procedure as an argument.
  • An incorrect binding binds the medium during a procedure that is actually called.

Deep binding.

Here f3 () gets the environment f1 () and prints the value x as 10, which is the local variable f1 ().

Invalid binding.

f3 () is called in f2 () and therefore gets the environment f2 () and prints the value x as 6, which is local to f2 ()

+5
source

β€’ The environment of the call operator that receives the past routine (shallow binding)

β€’ An environment for defining a past routine (deep binding).

In some cases, a subroutine that declares a subroutine also passes the subroutine as a parameter. In these cases, deep binding and special binding are the same.

0
source

All Articles