Javacsitp

  • Short Note: ทำให้ Javascript method return เป็น Promise แบบง่ายๆ

    ปกติแล้วเราจะให้ Javascript method return ออกมาเป็น Promise เราต้องเขียนประมาณนี้ https://gist.github.com/thangman22/4e70d41e4cbfa12ed195d34c7c4c84d3/edit คราวนี้มันยาวไปเราเขียนแบบนี้ก็ได้ https://gist.github.com/thangman22/522e0ee9dfa07d7a61651a22ce355590 แต่ด้วย Async Await เราจะทำให้เขียนได้ดูงงน้อยลงแบบนี้ เพราะว่า ตัว Method ที่เป็น Async จะ return เป็น Promise อยู่แล้ว https://gist.github.com/thangman22/d14e80e8fcecfde5b74bd375f627f089