Javascript configuration object advice -
this isn't problem code, it's more of advice question. found below code on better practices javascript.
if had code below, usage script pull labels , settings etc.
carousel = function(){ var config = { css:{ classes:{ current:'current', scrollcontainer:'scroll' }, ids:{ maincontainer:'carousel' } } labels:{ previous:'back', next:'next', auto:'play' } settings:{ amount:5, skin:'blue', autoplay:false } }; function init(){ }; function scroll(){ }; function highlight(){ }; return {config:config,init:init} }();
you've detailed javascript design pattern called revealing module pattern - it's nice pattern grips allows write js in more oop fashion.
to access properties simple traverse through object, example:
carousel.config.labels.previous
see this fiddle
Comments
Post a Comment