浅&Deep Binding - 这个程序会打印什么? [英] Shallow & Deep Binding - What would this program print?

查看:15
本文介绍了浅&Deep Binding - 这个程序会打印什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道该怎么做...

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);
};

对于以下两种装订方法中的每一种,程序将打印什么?A) 浅绑定B) 深度绑定

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

感谢您的帮助!

推荐答案

深/浅绑定只有在过程可以作为参数传递给函数时才有意义.

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

  • 深度绑定在过程通过时绑定环境作为论据.
  • 浅绑定 绑定环境过程实际上被调用.
  • Deep binding binds the environment at the time a procedure is passed as an argument.
  • Shallow binding binds the environment at the time a procedure is actually called.

这里f3()获取f1()的环境,并将x的值打印为10这是 f1() 的局部变量.

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

f3()f2() 中被调用,因此获取 f2() 的环境并将 x 的值打印为 6这是本地 f2()

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

这篇关于浅&Deep Binding - 这个程序会打印什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆