Skip to content

Instantly share code, notes, and snippets.

@jubalm
Created June 10, 2015 04:17
Show Gist options
  • Save jubalm/8b39a30913da4da0c3a0 to your computer and use it in GitHub Desktop.
Save jubalm/8b39a30913da4da0c3a0 to your computer and use it in GitHub Desktop.
Code Etiquette: JavaScript

JavaScript Etiquette

Javascript Pragma

These practices revolves around the pragmatic approach to JavaScript coding which deals with practical usage rather than theoretical considerations.

The "use strict" pragma?

"use strict" is a language construct that tells the compiler how to interpret the document. If you are familiar with html doctype or character encoding, they serve similar purposes.

General Considerations

  • it works
  • it's easy to understand
  • it should be easy to do

Namespacing

  • Use long, descriptive variable and method names
var bindAllButtons = function() { /**/ },
	redirectURL = 'http://www.isobarhub.com',
	redirectButtonClass = '.button--redirect';

Encapsulation

Encapsulation includes the idea that the data of an object should not be directly exposed. Instead, callers that want to achieve a given result are coaxed into proper usage by invoking methods (rather than accessing the data directly).

var person = {
	"fullName": "Jubal Mabaquiao"
}

alert(person.fullName); // Jubal Mabaquiao
person.fullName = "Juan Dela Cruz"
alert(person.fullName); // Juan Dela Cruz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment