Created
October 13, 2010 15:42
-
-
Save websymphony/624295 to your computer and use it in GitHub Desktop.
JSfunctionSkeleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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