Skip to content

Instantly share code, notes, and snippets.

View da-vaibhav's full-sized avatar
⚛️
available for hire

vaibhav da-vaibhav

⚛️
available for hire
View GitHub Profile
@da-vaibhav
da-vaibhav / README.md
Last active February 24, 2016 13:57 — forked from mbostock/README.md
Underscore’s Equivalents in D3

Collections

each(array)

Underscore example:

_.each([1, 2, 3], function(num) { alert(num); });
@da-vaibhav
da-vaibhav / gist:931c2a95ce93bc6ef06b
Last active August 30, 2015 19:44
Simple node.js code style tips to improve code quality

Whether you use 2 spaces or 4 spaces, there are a few simple things that can make your node.js code easier to read. We've been using them in all the hapi modules for over 4 years now to great results. This list is by no means complete but it highlights the most useful elements that will give you immediate value in reducing bugs.

Required modules

JavaScript makes it harder than most languages to know where variables are coming from. Variables assigned required modules are particularly important because they represent a singleton object shared with the entire application. There are also globals and module globals, along with function variables and arguments.

Traditionally, variables starting with an uppercase letter represent a class that must be instantiated using new. This was an important semantic in the early days of JavaScript but at this point, if you don't know Date requires new Date() you are probably very new. We have adopted Upper Camel Case variable names for all module global variables