Skip to content

Instantly share code, notes, and snippets.

@davidrichards
Created June 26, 2012 01:23
Show Gist options
  • Save davidrichards/2992489 to your computer and use it in GitHub Desktop.
Save davidrichards/2992489 to your computer and use it in GitHub Desktop.
A basic closure example. Also here: http://bost.ocks.org/mike/chart/
function chart() {
var width = 720, // default width
height = 80; // default height
function my() {
// generate chart here, using `width` and `height`
}
my.width = function(value) {
if (!arguments.length) return width;
width = value;
return my;
};
my.height = function(value) {
if (!arguments.length) return height;
height = value;
return my;
};
return my;
}
function SingleSelect() {
// These variables won't get lost to the select view
var x = 1;
function self() {
// initialization code goes here, if necessary
// like some jquery setup of the select
}
self.change = funciton() {
}
return self;
}
var mySelect = SingleSelect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment