Rojakcoder
Of Linux, Programming, and Singaporean Ramblings

A little lesson on binding

Wed, Sep 28, 2016

I’ve been writing JavaScript for the past 10 years for my work, and there are still things in the language that trips me up. A very good example is on binding.

Given the setup below, I would have been a little hesitant as to what the right answer is.

Read more

More tips for BackboneJS

Fri, Feb 19, 2016
Some time back when researching for Backbone JS stuff (I can't remember for what now), I encountered this post Lessons learned while working with Backbone.js. This post was written a few years back, but I was still able to glean some gems from it. Specifically, the section "Simplified Object Copying" was something that could be applied on plain vanilla JavaScript. The other section "Changing in referenced object does not trigger events"
Read more

Backbone Events

Tue, Oct 27, 2015
Backbone events are a powerful way to write responsive user interfaces with fewer lines of codes. This article attempts to give a detailed breakdown of the events and the parameters available for the callback functions. The results in this article are applicable for version 1.2.3 of Backbone.js The test is performed by instantiating instances of ExperimentModel extended from Backbone.Model and ExperimentCollection extended from Backbone.Collection. The model is first added to the collection to test "
Read more

Back to Basics

Sun, Sep 27, 2015

When I started my formal education in computer science, I had to take a module on programming with the C language. I remember this was a module that caused many of my peers to re-think their decision to study computer engineering; the concept of pointers was so foreign to many of them that even the smart ones scored poorly.

Read more

Download JSON as a Text File

Thu, Sep 18, 2014

As a Web developer, I sometimes find a need to download some huge JSON object into a text file.

Modern browsers now come with some form of developer tool/console to help debug the monstrous amount of JavaScript in the Web page. For Chrome and Firefox, I simply press F12 to bring up the console. From the console, you can naturally copy the JSON object in its string form by first converting the object into a string like so:

JSON.stringify(obj);

Then highlight the output from the developer console and press Ctrl-C to copy. The trouble comes in when the object is huge - to the tune of thousands of properties.

When an object gets to that size, you will need to scroll to be able to select the complete output. Scrolling the console is itself a tiresome task with text that small. Moreover you run the risk of “over scrolling” such that you select two objects rather than one because you can’t tell the difference when they are simply chunks of text.

The best solution is to download the JSON as a text file and then use/manipulate the JSON from the file.

The way to do this is to create a function like this:

Read more

Solving the Mystery Behind Alternating Failed Tests in QUnit

Tue, Aug 14, 2012

I’ve recently started using QUnit for my JavaScript testing. It’s a unit testing framework for JavaScript. It’s quite an easy framework to learn and I strongly encourage everyone who is doing any decent JavaScript coding to use it or any one of the myriad frameworks out there.

One of the strange problems I faced with QUnit is a strange phenomenon where a custom written plugin fails the test on every alternate invocations of the test.

Read more

JSON Object With Trailing Comma

Sat, Nov 14, 2009

As any respectable JavaScript developer will know, JSON has become the de facto method of holding objects and passing arguments, even using it as a name-spacing mechanism.

Being the conscientious (and careless) programmer that I am, in my e-learning application that I’m developing at the moment, where I’m heavily using JSON, I made a conscious choice to always leave a comma at the end of the last member-value pair like so:

Read more
Page 1 of 1