Public
Edited
Feb 2, 2023
Insert cell
Insert cell
Insert cell
res = [0]
Insert cell
{ // ยิ่งเรียกหลายที ก็ยิ่งเพิ่มขึ้นเรื่อยๆ
// หรือเมื่อ res เปลี่ยน ก็จะถูก run ซ้ำ
// res.length = 0 // ถ้าจะ clear ทุกครั้ง
for (let i of [1,2,3]) {
res.push(2*i)
}
return res
}
Insert cell
{ return res } // วิธีเรียกดูค่า res ตอนนี้ (ถ้าข้างบนไม่ update
Insert cell
{ res.length=0 } // วิธีลบ clear ค่า
Insert cell
res2 = [...res, ...res]
Insert cell
Insert cell
// initiate เพื่ออ้างถึง และจะถูกแก้จาก cell อื่นได้
mutable result = 0
Insert cell
{ // ถ้าไม่ใส่ mutable ก็จะ reactive เมื่อ result เปลี่ยน (ปกติ)
return result + 1
}
Insert cell
{ // non-reactive เป็นคนสั่งแก้คนอื่น แต่ไม่รับถ้า result ถูกคนอื่นแก้
mutable result = 10
return mutable result
}
Insert cell
{ // มีได้หลายอัน ไม่ตีกัน
mutable result = 30
return mutable result
}
Insert cell
// x = 10 อย่างเดียวไม่ได้
mutable x = 10
Insert cell
{ // ต้องระบุตั้งแต่ตอนสร้าง ถึงจะเรียก mutable ตอนใช้ได้
let y = 2 * mutable x
return y
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more