Last active
December 15, 2015 16:19
-
-
Save deniswolf/5288647 to your computer and use it in GitHub Desktop.
build on idea of promises
POC of framework full of chained callbacks
This file contains hidden or 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
// kommunism.js | |
// build on false promises | |
// to chain callbacks | |
function PrimitiveKommunism(computationFunction, thisArg){ | |
// todo: return promise that will resolve when computation is done | |
var someInnerComputationsResult = computationFunction.apply(thisArg, _.toArray(arguments)); | |
function Kommunism(currentCallback, optionalCallbackParameters){ | |
var currentArguments = _.toArray(arguments).slice(1); | |
var argumentsToPass = [someInnerComputationsResult].concat(currentArguments); | |
currentCallback.apply(this,argumentsToPass); | |
return Kommunism; | |
} | |
return Kommunism; | |
} | |
function callBack(){ | |
console.log('callback',arguments); | |
} | |
socialism = new PrimitiveKommunism(function(){return 'Wait for the future, Komrade!'}) | |
socialism(callBack,'z','x')(callBack)(callBack,1)(callBack,2)(callBack,3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why do you need _
http://jsfiddle.net/3k2TD/9/