Naman Goel

Software Engineer at Obsessed with Javascript

Page 3

Creating Magic with Object.create().

Javascript’s approach to objects can be quite daunting. There are a few ways to achieve the goal of making an object factory. In general, though, it comes down to two ways.

1: Factory Function

var makeObject = function(){
  var obj = {};
  obj.prop = "object name";
  return obj;

This is probably the most explicit way of creating an object constructor or the closest thing to a class in a javascript. (The Pseudo-classical way is another but we’re not talking about that here.)

The interesting part comes when you want to add a prototype to this object. The code turns to something like this:

var makeObject = function(){
  var obj = Object.create(prototype); //pass in the prototype object
  obj.prop = "object name";
  return obj;

(If you don’t know about prototypes, you should read about that here. The interesting part is the optional, second argument of Object.create. Head over to...

Continue reading →

Using Handlebars.js with Sails.js

Sails.js is a great framework that is easy to learn, well-documented and getting a lot of traction in the market. Sails.js is based on Ruby on Rails and follows its philosophy of convention over configuration. There is a lot of magic and things just work. That said, the magic seems to make more sense here than in Rails, and it usually doesn’t surprise you. (That’s a good thing.)

The problem is that with convention over configuration philosophy comes the assumption that most people will stick to defaults. As a result, straying from the expected defaults can land you in a lot unchartered territory with little community help and almost no documentation.

In my recent project, Scribbler I strayed from the conventional Sails.js path on multiple occasions and after much strife, I emerged victorious. Here’s my story.

Easy beginnings

Right off the bat, Sails is super easy to work with, as is...

Continue reading →

Why Gulp.js is awesome, and how to use it with Sails.js

A few months ago, the folks over at Fractal, decided to reinvent Grunt. After identifying and fixing the problems with Grunt, they ended up with Gulp.js

And how do you think the internet responded? You’re right, it immediately turned into a flame war. No one wanted to enjoy the fact there was now more choice. Immediately people started parsing Gulp or rejecting it outright.

I’m not going to spoil all the fun. When, lives are not at stake, wars can be fun! I’m here to praise Gulp and tell you why you should probably switch.

Let me start with what isn’t great about Gulp. It can all be attributed to its newness –

  • It doesn’t have as many plug-ins
  • It doesn’t have as much documentation
  • It’s not integrated into popular tools and frameworks like Grunt
  • It’s probably hard for people who don’t know any javascript, (but Grunt isn’t any easier)

On the other hand, there are a bunch of things...

Continue reading →