版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
其实很多英文名词对应的中文名词我们很好理解,也很容易理解他的用处。但是有很多名词恰恰就是英文的,而我们因为英语水平的局限,很难将这些英文名词翻译到位,也就导致很容易理解的名词经常困扰着我们。
那今天的主角是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中声明,也没有传递。它是一个“自由变量”。