Instantly share code, notes, and snippets.

Lucas lucastan

View GitHub Profile
@lucastan
lucastan / JavaScript Class Patterns.md
Last active Feb 22, 2016
Concise discussion on JavaScript class patterns, the whys and don'ts.
View JavaScript Class Patterns.md

Throughout this article, I will use Java's Object-Oriented Programming terminologies such as static, private and public.

Pattern 1: Self-construction

This pattern exploits scoping to allow for private and public fields and methods. It is named as Self-construction because the class function (or constructor) has to assign instance methods one by one.

View JavaScript Closure Pitfalls.md

This describes the common mistake with using closures in JavaScript.

A function defines a new environment

Consider:

function makeCounter()
{
  var obj = {counter: 0};
@lucastan
lucastan / JavaScript Implicit Boolean Conversion.md
Created Apr 19, 2013
Describes the behavior of implicit boolean conversion in JavaScript
View JavaScript Implicit Boolean Conversion.md

Implicit Boolean Conversion in JavaScript

Only the following values are considered false:

  • null
  • undefined
  • '' (empty string)
  • 0
  • NaN
  • false