Skip to content

Instantly share code, notes, and snippets.

@IUnknown68
Last active August 29, 2015 14:06
Show Gist options
  • Save IUnknown68/d344b9a1532d0b174b46 to your computer and use it in GitHub Desktop.
Save IUnknown68/d344b9a1532d0b174b46 to your computer and use it in GitHub Desktop.
Array where you can add methods which will be called on each entry.
//==============================================================================
function DelegateCollection() {
for (var i = 0, m = arguments.length; i < m; i++) {
this.addCall(arguments[i]);
}
}
//------------------------------------------------------------------------------
DelegateCollection.prototype = new Array;
DelegateCollection.prototype.addCall = function(name) {
this[name] = function() {
var args = arguments;
this.forEach(function(item) {
try {
item[name].apply(item, args);
}
catch(e) {
console.error('DelegateCollection::' + name);
console.error(e);
}
});
return this;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment