Skip to content

Instantly share code, notes, and snippets.

@websymphony
Created October 13, 2010 15:42
Show Gist options
  • Save websymphony/624295 to your computer and use it in GitHub Desktop.
Save websymphony/624295 to your computer and use it in GitHub Desktop.
JSfunctionSkeleton
var skeleton = function(){
// private variables *******
var x;
// private functions
// initialization *******
( function init () {
// only call private functions or variables!
} ) ();
// public API *******
return {
methodName : function () {
},
methodName : function () {
}
}
} ();
/*
* Example Usage
*/
var Composers = function(){
// private variables *******
var eras = {
classical : [ "Bach", "Mozart", "Haydn" ],
romantic : [ "Beethoven", "Chopin", "Wagner" ],
modern : [ "Bloch", "Gorecki", "Nielsen", "Britten" ]
};
// private functions
var randomForEra = function( era ) {
var arraySize = eras [ era ].length;
return Math.floor( Math.random() * ( arraySize ) );
};
// initialization *******
( function init () {
// only call private functions or variables!
eras.classical.sort();
eras.romantic.sort();
eras.modern.sort();
} ) ();
// public API *******
return {
representative : function (era) {
return eras[ era ][ randomForEra( era ) ];
}
}
} ();
console.log( Composers.representative( 'modern' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment