Skip to content

Instantly share code, notes, and snippets.

@vasuman
Last active December 17, 2015 11:59
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 vasuman/5606716 to your computer and use it in GitHub Desktop.
Save vasuman/5606716 to your computer and use it in GitHub Desktop.
Augmented Chaining
//The all augmentations must use this as the basic object
function baseChainObject() { };
baseChainObject.prototype.chainExecute = function (methodName, args) {
for(var i = this.__proto__; i[methodName]; i = i.__proto__) {
//Call with context
i[methodName].apply(this, args);
}
};
//Augments the prevLink with nextLink
//it returns a modified constructor that is ideally
//assigned back to the first argument "nextLink"
chainTogether = function (nextLink, prevLink) {
//Creating a modified constructor
var modCons = function () {
prevLink.apply(this, arguments);
nextLink.apply(this, arguments);
};
//Assign prototype
modCons.prototype = nextLink.prototype;
//Link up the prototype chains!!
modCons.prototype.__proto__ = prevLink.prototype;
return modCons;
};
//Node-js
exports.bco = baseChainObject;
exports.ct = chainTogether;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment