Instantly share code, notes, and snippets.

Lucas lucastan

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

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

This describes the common mistake with using closures in JavaScript.

A function defines a new environment


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

Implicit Boolean Conversion in JavaScript

Only the following values are considered false:

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