WillFuqua

Splitting Thai words with Browser APIs

One of the difficulties for students learning the Thai language is the lack of spaces between words. For example, here is a simple sentence in Thai:

สวัสดีครับกินข้าวหรือยัง

After some time, students start to recognize the shapes of the words and it becomes effortless to read. Before that time, however, it's quite a struggle!

I found a neat trick yesterday for splitting Thai sentences into words with JavaScript in Chrome. There's no native API for understanding Thai text, but it's possible to piggyback on top of the browser's text selection APIs.

When a word is double-clicked in the browser, the browser will select that word---and continue.

tagged as , and

Native JavaScript Promises and Browser APIs

One of the interesting evolutions of mainstream JavaScript development has been the widespread adoption of Promises. Promises simplify asynchronous code. Since JavaScript in the browser uses a single-threaded, callback-based programming model, asynchronicity is everywhere.

The Problem with Asynchronicity

Asynchronous patterns are great for keeping UIs responsive and non-blocking, but they have a cost: asynchronous JavaScript code tends to be highly nested, which hurts readability. Additionally, because you can't catch errors that are thrown inside callbacks from outside those callbacks, error handling needs to be spread throughout every level of nesting.

When we use Promises, our code structure is flattened, and our error handling continue.

tagged as , , and