execution context 执行上下文
Each execution context has an associated variable object upon which all of its defined variables and functions exist.
浏览器里最外层的执行上下文的variable object是window,
每个函数也有自己的execution context
scope chain 作用域链
最开始的作用域链是当前正在执行的代码,最末尾的是global context
寻找variable总是从scope chain的开头往后找
一个函数里面的execution context是arguments和local variables
外面不能访问里面,里面可以访问外面
下面例子的scope chain里有3个context
swapColors -> changeColor -> global context
var color = "blue";
function changeColor() {
let anotherColor = "red";
function swapColors() {
let tempColor = anotherColor;
anotherColor = color;
color = tempColor;
// color, anotherColor, and tempColor are all accessible here
}
// color and anotherColor are accessible here, but not tempColor
swapColors();
}
// only color is accessible here
changeColor();
Object.freeze()
声明一个不能被改变的对象
const o3 = Object.freeze({});
o3.name = 'Jake';
console.log(o3.name); // undefined