diff --git a/1-js/11-async/01-callbacks/article.md b/1-js/11-async/01-callbacks/article.md index 57115a909..bab5811a9 100644 --- a/1-js/11-async/01-callbacks/article.md +++ b/1-js/11-async/01-callbacks/article.md @@ -1,68 +1,67 @@ +# บทนำ: callback -# Introduction: callbacks +```warn header="ตัวอย่างในบทนี้ใช้ browser methods" +เพื่ออธิบาย callback, promise และ concept ที่เกี่ยวข้อง เราจะหยิบ browser methods มาใช้ โดยเฉพาะการโหลด script และจัดการ document เบื้องต้น -```warn header="We use browser methods in examples here" -To demonstrate the use of callbacks, promises and other abstract concepts, we'll be using some browser methods: specifically, loading scripts and performing simple document manipulations. +ถ้ายังไม่คุ้นเคยกับพวกนี้และอ่านแล้วงง ลองข้ามไปอ่าน [ส่วนถัดไป](/document) ของ tutorial ก่อนก็ได้ -If you're not familiar with these methods, and their usage in the examples is confusing, you may want to read a few chapters from the [next part](/document) of the tutorial. - -Although, we'll try to make things clear anyway. There won't be anything really complex browser-wise. +แต่เราจะพยายามอธิบายให้ชัดอยู่ดี — ไม่มีอะไรที่ซับซ้อนมากในแง่ browser ``` -Many functions are provided by JavaScript host environments that allow you to schedule *asynchronous* actions. In other words, actions that we initiate now, but they finish later. +JavaScript host environment มีฟังก์ชันหลายตัวที่ช่วยให้เรา schedule งาน *asynchronous* ได้ — พูดง่ายๆ คือ "สั่งให้ทำ แต่ไม่ต้องรอ ทำเสร็จแล้วค่อยบอก" -For instance, one such function is the `setTimeout` function. +ตัวอย่างที่คุ้นกันดีที่สุดคือ `setTimeout` -There are other real-world examples of asynchronous actions, e.g. loading scripts and modules (we'll cover them in later chapters). +งาน asynchronous ในชีวิตจริงยังมีอีก เช่น การโหลด script หรือ module (จะพูดถึงในบทหลัง) -Take a look at the function `loadScript(src)`, that loads a script with the given `src`: +ลองดูฟังก์ชัน `loadScript(src)` ที่โหลด script จาก `src` ที่กำหนด: ```js function loadScript(src) { - // creates a