I am Hack Sparrow
Captain of the Internets.

JavaScript .bind() vs .apply() and .call()

So, what's the point of .bind() when we already have .apply() and .call()? For those not familiar with .bind(), .apply(), and .call(), here is a quick summary with this object [code] var fruit = { name: 'Apple' } [/code] and this function [code] function showDetails(size, price) { console.log(this.name + ' ' + size + ': $' + price + '/kg') } [/code] on mind. All three of them are function meth ...

Node.js Async Programming

One of the most important highlights of Node.js is that it is asynchronous. At the same time its async nature can also become its Achilles' heel - if one doesn't know how to manage the nested async callback functions. Take a look at this piece of code with three levels deep async callbacks. [code] var fs = require('fs'); var http = require('http'); var path = './headers.txt'; // i. check if headers.txt exists fs.stat(path, function(err, stats) { if (stats == undefined) { // ii. ...