@@ -5,7 +5,7 @@ title: Scalacheat
55partof : cheatsheet
66
77by : Brendan O'Connor
8- about : ขอบคุณ <a href="http://brenocon.com/">Brendan O'Connor</a>, สำหรับ cheatsheet นี้มีวัตถุประสงค์เพื่ออ้างอิ่งอย่างง่ายสำหรับโครงสร้างประโยคของ Scala, Licensed by Brendan O'Connor under a CC-BY-SA 3.0 license.
8+ about : ขอบคุณ <a href="http://brenocon.com/">Brendan O'Connor</a>, สำหรับ cheatsheet นี้มีวัตถุประสงค์เพื่ออ้างอิงอย่างง่ายสำหรับโครงสร้างประโยคของ Scala, Licensed by Brendan O'Connor under a CC-BY-SA 3.0 license.
99
1010language : " th"
1111---
@@ -14,15 +14,15 @@ language: "th"
1414
1515{{ page.about }}
1616
17- | <span id =" variables " class =" h2 " >ตัวแปล </span > | |
18- | ` var x = 5 ` | ค่าตัวแปล |
17+ | <span id =" variables " class =" h2 " >ตัวแปร </span > | |
18+ | ` var x = 5 ` | ค่าตัวแปร |
1919| <span class =" label success " >Good</span ><br > ` val x = 5 ` <br > <span class =" label important " >Bad</span ><br > ` x=6 ` | ค่าคงที่ |
2020| ` var x: Double = 5 ` | type ที่ชัดเจน |
2121| <span id =" functions " class =" h2 " >ฟังก์ชัน</span > | |
2222| <span class =" label success " >Good</span ><br > ` def f(x: Int) = { x*x } ` <br > <span class =" label important " >Bad</span ><br > ` def f(x: Int) { x*x } ` | กำหนดฟังก์ชัน <br > ซ้อนความผิดพลาด : ไม่มีการ return Unit ของฟังก์ชัน;<br > เป็นสาเหตุให้เกิดข้อผิดพลาดได้ |
2323| <span class =" label success " >Good</span ><br > ` def f(x: Any) = println(x) ` <br > <span class =" label important " >Bad</span ><br > ` def f(x) = println(x) ` | กำหนดฟังก์ชัน <br > ไวยกรณ์ผิดพลาด : จำเป็นต้องกำหนดค่าสำหรับทุกๆ arg |
2424| ` type R = Double ` | นามแฝงของ type |
25- | ` def f(x: R) ` vs.<br > ` def f(x: => R) ` | ส่งผ่านฟังก์ชันโดยค่าของข้อมูล <br > ส่งผ่านฟังก์ชันโดยชื่อ (lazy parameters) |
25+ | ` def f(x: R) ` vs.<br > ` def f(x: => R) ` | call-by-value <br > call-by-name (lazy parameters) |
2626| ` (x:R) => x*x ` | ฟังก์ชันที่ไม่ระบุชื่อ |
2727| ` (1 to 5).map(_*2) ` vs.<br > ` (1 to 5).reduceLeft( _+_ ) ` | ฟังก์ชันที่ไม่ระบุชื่อ : ตำแหน่งของขีดล่างตรงกับตำแหน่งของ arg |
2828| ` (1 to 5).map( x => x*x ) ` | ฟังก์ชันที่ไม่ระบุชื่อ : เพื่อใช้ arg สองครั้งต้องตั้งชื่อ |
0 commit comments