變量、綁定與手柄

對象常量的屬性能夠改變的?

`值常量看似是「值不能變」意思,事實符號綁定不變,由於變量只是個手柄(地址引用),非容器
編程

`對象常量,不是對象內容不變,是對象引用(手柄)不能變
bash

Object Declarations with const A const declaration prevents modification of the binding, not of the value.
ide

const聲明防止綁定的修改,而不是值的修改
函數

That means const declarations for objects don’t prevent modification of those objects. For example:
ui

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:
spa

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.
code

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);
// → dark複製代碼

3 可見符號變量只是一個引用/手柄,而非容器

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.
ip

符號綁定與變量概念的區別

一個技術實現的概念,例如編譯器,一個是編程的概念,是高級語言的應用概念
rem

爲何須要符號綁定

  • 中間計算
  • 複雜的計算(計算集中,數據集中)都是多步的
  • 符號能夠抽象,表達複雜多步計算,符號種類有變量,表達,函數和類對象等多種粒度
相關文章
相關標籤/搜索