MyCarousel('firstId');
MyCarousel('secondId');
MyCarousel = (function(){
elementsCache = {};
function doInitJob(elem) {
console.log("initializtion", elem);
};
function doServiceJob(elem) {
console.log("service", elem);
};
return function(selector) {
if (!elementsCashe[selector]) {
elementsCashe[selector] = document.querySelector(selector);
doInitJob(elementsCashe[selector]);
} else {
doServiceJob(elementsCashe[selector]);
}
}
})();