对象常量的属性可以改变的?
`值常量看似是“值不能变”意思,事实符号绑定不变,因为变量只是个手柄(地址引用),非容器
`对象常量,不是对象内容不变,是对象引用(手柄)不能变
Object Declarations with const
A const declaration prevents modification of the binding, not of the value.
const声明防止绑定的修改,而不是值的修改
That means const declarations for objects don’t prevent modification of
those objects. For example:
const person = {
name: "Nicholas"
};
// works 改内容不出错
person.name = "Greg";
// throws an error 改绑定出错
person = {
name: "Greg"
};
变量与符号绑定技术
1 符号绑定一个计算结果
To catch and hold values, JavaScript provides a thing called a
binding, or variable:
let caught = 5 * 5;
The previous statement creates a binding called caught and uses it to grab
hold of the number that is produced by multiplying 5 by 5.
2 符号可以解绑定
When a binding points at a value, that does not mean it is tied to that
value forever. The = operator can be used at any time on existing bindings to
disconnect them from their current value and have them point to a new one.
let mood = "light";
console.log(mood);
// → light
mood = "dark";
console.log(mood);
// → dark3 可见符号变量只是一个引用/手柄,而非容器
You should imagine bindings as tentacles, rather than boxes. They do not
contain values; they grasp them—two bindings can refer to the same value.
A program can access only the values that it still has a reference to. When
you need to remember something, you grow a tentacle to hold on to it or you
reattach one of your existing tentacles to it.
符号绑定与变量概念的区别
一个技术实现的概念,例如编译器,一个是编程的概念,是高级语言的应用概念
为什么需要符号绑定
- 中间计算
- 复杂的计算(计算集中,数据集中)都是多步的
- 符号可以抽象,表达复杂多步计算,符号种类有变量,表达,函数和类对象等多种粒度