Having an object to store data.
var store = {
elements: [],
eventsEnabled: true,
addElement: function(element) {
this.elements.push(eleme
Further to @Jamiec's suggestion, you could also look at passing the event function in as well:
var store = {
elements: [],
addElement: function(element, callback) {
this.elements.push(element);
if (callback !== undefined) {
callback();
// Common code that triggers event, calls handlers... whatever
alert("I'm Common Event Code");
}
}
};
Used as such:
setInterval(function() {
store.addElement('hello', function(){ alert("I'm Special Event Code!"); });
}, 12000);
Thus, if an event is needed, you can pass it in, else just leave it out.