Lyndon Chun

Data Structures in JavaScript - Part 1

A stack is one of the easiest data structures to implement in JavaScript as there are native Array methods that we can use for stacks. What is a stack anyways? To put it simply, it refers to a data structure where items are stored in the order they are added like an array, but the last item in a stack is the first item to be removed, and the first item is the last item to be removed (last-in, first-out, or first-in, last-out principle).

read more ...

What's this - Part 2

In the previous, we looked at two important rules that determine where the “this” keyword points to in JavaScript. However, near the end we also explored situations where the “this” keyword’s binding is completely lost when passed to another function as a callback. How can we remedy such a situation so that we have finer control over the “this” keyword’s binding and take advantage of the dynamic aspect of JavaScript even more?

read more ...

What's this - Part 1

The “this” keyword in JavaScript is probably one of the most challenging concepts to grasp and understand because it is what makes the “dynamic” aspect of the JavaScript even more dynamic. The way that the same word is used in English is not really different from its usage in JavaScript. What would you say if someone asked you to explain what the word “this” means in English? You would probably say that it depends on when and where you say the word, and this is exactly the case with the “this” keyword in JavaScript. The “this” keyword will resolve to different values depending on call-site of a function where the function is executed.

read more ...

Good old closure in JavaScript - Part 2

Did the first post on closure sound simple enough or over-complicated? To some of you, the example and explanation might have sounded too straight-forward to an extent that some of you might be thinking, “Ok, that sounds easy and simple, but how is this actually used in actual code?”. As I said at the beginning of the post, closure is used all over the place, and you might have been using it all along in your projects without knowing that what you wrote involved the concept of closure.

read more ...

Good old closure in JavaScript - Part 1

My first encounter with closure was when I was working on a simple static web page that solely relied on jQuery for its behaviours.

read more ...