Skip to content

Instantly share code, notes, and snippets.

View raorao's full-sized avatar

Srinivas Rao-Mouw raorao

  • San Francisco, CA
View GitHub Profile
@raorao
raorao / closures.js
Last active December 28, 2015 06:09
Here's my attempt at explaining closures in JavaScript.
// As I've been know to yell, JavaScript is a stupid language, and I don’t mean that as an insult.
// For example, where Ruby has 50-ish enumerable methods to iterate over collections,
// JS has, basically, two. But that’s okay! That just means you have to build any complicated
// logical structures yourself in JavaScript, which makes your code more transparent and flexible.
// One important structure you often find yourself building from scratch is private functionality
// in object oriented programming. JavaScript closures are one way to achieve that goal.
var counter = (function() {
var currentCount = 0;
return {
repository available at: https://github.com/raorao/ar-student-schema
For this challenge, I created a simple Students table using AR migration, populated a student object with basic methods and validations.