Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created May 9, 2012 21:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwaldron/2648835 to your computer and use it in GitHub Desktop.
Save rwaldron/2648835 to your computer and use it in GitHub Desktop.
// This will create constructed instances that can be easily extended
function Chart( width, height ) {
if ( !(this instanceof Chart) ) {
return new Chart( width || null, height || null );
}
this.width = width || 720;
this.height = height || 80;
// construct your charts here...
}
Chart.prototype.width = function( value ) {
if ( !arguments.length ) return this.width;
this.width = value;
return this;
};
Chart.prototype.height = function( value ) {
if ( !arguments.length ) return this.height;
this.height = value;
return this;
};
// This is JUST a function object with "static" expando properties
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment