I'am a JavaScript developer,I'd like to make some contributions for js open source. I love coding!
taosin / blog Goto Github PK
View Code? Open in Web Editor NEWmy Blog
my Blog
I'am a JavaScript developer,I'd like to make some contributions for js open source. I love coding!
作用域是一套用于确定在何处以及如何查找_变量_(标识符)的规则。也可以理解为限定这个变量的可用性的_代码范围_。
要理解作用域,首先可以了解下 引擎、编译器的作用。
来自《你不知道的JavaScript(上)》
作用域链:当访问一个变量(标识符)时,解释器首先会在当前作用域进行查找,如果未找到,就会去上级作用域中查找,直到找到该变量或者到达最顶层的作用域(也就是全局作用域),这时就形成了作用域链。
作用域链的顶端是全局作用域,也就是window
,在window
中顶域的变量就会绑定到全局作用域中。
代码如下:
// 全局作用域,有一个标识符:foo。
function foo(a){
// foo 所创建的作用域,其中有三个标识符:a、bar和b。
var b = a * 2;
function bar (c) {
// bar 所创建的作用域,只有一个标识符: c。
console.log(a, b, c);
}
bar(b * 3);
}
foo(2);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.