Last active
August 29, 2015 14:06
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================== | |
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