什么是free variable

其实很多英文名词对应的中文名词我们很好理解,也很容易理解他的用处。但是有很多名词恰恰就是英文的,而我们因为英语水平的局限,很难将这些英文名词翻译到位,也就导致很容易理解的名词经常困扰着我们。

那今天的主角是free variable。

我把他叫为自由变量。

用英文可以这么解释它:

If a name is bound in a block, it is a local variable of that block. If a name is bound at the module level, it is a global variable. (The variables of the module code block are local and global.) If a variable is used in a code block but not defined there, it is a free variable.

最主要我觉得是最后一句,如果一个变量在一个代码块中使用,而没有在那里定义它,那它就是一个自由变量。

比如:

define(function(require, exports, module) {
  // The module code goes here

});

这里的require,exports,module就是free variable.

 

又比如:

Gol.prototype._ensureInit = function() {
    ...
    var _this = this;
    var setDim = function() {
        _this.w = _this.canvas.clientWidth;
        _this.h = _this.canvas.clientHeight;
        _this.canvas.width = _this.w;
        _this.canvas.height = _this.h;
        _this.dimChanged = true;
        _this.draw();
    };
    setDim();
    window.addEventListener('resize', setDim);
    ...
};

变量-this没有在setDim中声明,也没有传递。它是一个“自由变量”。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yisun03

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值