Last active
December 17, 2015 11:59
-
-
Save vasuman/5606716 to your computer and use it in GitHub Desktop.
Augmented Chaining
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
//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