Trying to get my head around OLOO pattern. Here's the fiddle which will make it easier to explain: https://jsfiddle.net/t0o5jnyL/
(function() {
return PushdownProto = {
init: function(elem) {
this.element = $(elem);
this.btn = this.element.find('.js-pushdown-btn');
this.bindEvents();
},
open: function open() {
var panel = this.btn.data('panel');
this.btn.addClass('is-active');
$('#' + panel).addClass('is-active');
},
close: function close() {
var panel = this.btn.data('panel');
this.btn.removeClass('is-active');
$('#' + panel).removeClass('is-active');
},
toggle: function toggle(e) {
console.log(e);
if ($(e.target).hasClass('is-active')) {
this.close();
} else {
this.open();
}
},
bindEvents: function bindEvents() {
var self = this;
this.element.find('.js-pushdown-btn').on('click', $.proxy(self.toggle, this));
}
};
})();
(function() {
return PickerProto = {
init: function init(sector) {
var origin = sector + ' .js-pushdown1';
var destination = sector + ' .js-pushdown2';
Pushdown1 = Object.create(PushdownProto);
Pushdown1.init(origin);
Pushdown2 = Object.create(PushdownProto);
Pushdown2.init(destination);
}
}
})();
(function() {
var SectorPicker1 = Object.create(PickerProto);
SectorPicker1.init('.sector1');
var SectorPicker2 = Object.create(PickerProto);
SectorPicker2.init('.sector2');
})();
I've created a simple object called pushdown and created multiple objects (Pushdown1 and Pushdown2) linking to the pushdown object. These objects create a new object called PickerProto, which I would like to create new objects from.
If you look at the fiddle, you can see that the pushdowns on Sector 2 don't work and control the pushdowns from Sector 1.
I guess this is because it uses the same object. So my question is how to structure my code using OLOO pattern that allows modularity.
Hope that makes sense. And thanks in advance for any advice.