文章目錄
Properties
|
|
Assigning to a Property
|
|
Missing Properties
|
|
Note this does not mean that our object has a boat
property pointing to undefined
! It only has two properties, and neither of them is called boat
:
Recap
-
Properties are wires — a bit like variables. They both point at values. Unlike variables, properties start from objects in our universe.
-
Properties have names. Properties belong to particular objects. You can’t have more than one property with the same name on an object.
-
Generally, you can perform an assignment in three steps:
- Figure out which wire is on the left.
- Figure out which value is on the right.
- Point that wire to that value.
-
An expression like
obj.property
is calculated in three steps:- Figure out which value is on the left.
- If it’s
null
orundefined
, throw an error. - If that property exists, the result is the value its wire points to.
- If that property doesn’t exist, the result is
undefined
.
觀念小測驗
非常巧妙的例子:
|
|
|
|
- 寫出下方概念的程式碼
|
|