浅层和放大器;深绑定 - 什么会这个程序的打印? [英] Shallow & Deep Binding - What would this program print?

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

问题描述

我不知道如何做到这一点...

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.


  • 深绑定结合环境在过程传递时间
    作为参数。

  • 浅约束力结合环境在当时
    过程实际上是调用。

深度结合。结果
这里f3的()得到)f1的环境(并打印10 x的值是f1的本地变量()

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

浅的结合。结果
F3()被调用在f2的(),因此得到f2的环境(),并打印在6 x的值,它是本地到f2()

Shallow binding.
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()

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

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