Skip to content

Instantly share code, notes, and snippets.

View kad3nce's full-sized avatar

Jedidiah Hurt kad3nce

View GitHub Profile
# You Don't Know JS: Scope & Closures
# Chapter 1: What is Scope?
One of the most fundamental paradigms of nearly all programming languages is the ability to store values in variables, and later retrieve or modify those values. In fact, the ability to store values and pull values out of variables is what gives a program *state*.
Without such a concept, a program could perform some tasks, but they would be extremely limited and not terribly interesting.
But the inclusion of variables into our program begets the most interesting questions we will now address: where do those variables *live*? In other words, where are they stored? And, most importantly, how does our program find them when it needs them?
These questions speak to the need for a well-defined set of rules for storing variables in some location, and for finding those variables at a later time. We'll call that set of rules: *Scope*.
# Testing
* one
* two
* three
// Multiple Items and Event Monitoring Example
import com.hydrotik.queueloader.QueueLoader;
import com.hydrotik.queueloader.QueueLoaderEvent;
var imageContainer:Sprite = new Sprite();
addChild(imageContainer);
imageContainer.x = imageContainer.y = 25;
var _oLoader:QueueLoader = new QueueLoader();
require 'rubygems'
require 'ostruct'
# Ruby Gems
require 'haml'
require 'json'
require 'sinatra' unless defined?(Sinatra)
require 'bumble'
require 'movie'