Skip to content

Instantly share code, notes, and snippets.

@anutron
Created February 22, 2009 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anutron/68408 to your computer and use it in GitHub Desktop.
Save anutron/68408 to your computer and use it in GitHub Desktop.
Chain = new Class({
$chains: {},
getChain: function(key) {
this.$chains[key] = this.$chains[key] || {
$chain: [],
chain: function(){
this.getChain(key).$chain.extend(Array.flatten(arguments));
return this;
},
callChain: function(){
return (this.getChain(key).$chain.length) ? this.getChain(key).$chain.shift().apply(this, arguments) : false;
},
clearChain: function(){
this.getChain(key).$chain.empty();
return this;
}
};
return this.$chains[key];
}
});
(function(){
var methods = {};
['chain', 'callChain', 'clearChain'].each(function(method) {
methods[method] = function(){
return this.getChain('default')[method].apply(this, arguments);
};
});
Chain.implement(methods);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment