Skip to content

Instantly share code, notes, and snippets.

@kikill95
Last active October 19, 2019 07:33
Show Gist options
  • Save kikill95/14e5bf101c1b77babc8b431c8e498d9d to your computer and use it in GitHub Desktop.
Save kikill95/14e5bf101c1b77babc8b431c8e498d9d to your computer and use it in GitHub Desktop.
perform.js
//by Denys Pysmennyi
function perform() {
//TODO implement
}
perform(20, function(value) {
console.log(value) // 20
var param = 1;
console.log(param); // 1
return param;
})
.then('a', 'b', function(a, b, param) {
console.log(++param); // 2
return param;
})
.then(function(param) { // param === 2
console.log(++param); // 3
return param;
});
@kikill95
Copy link
Author

kikill95 commented Oct 17, 2019

// one of the solutions
function perform(...args1) {
	var func1 = args1.pop()
	var result = func1.apply(this, args1)
	return {
		then: function (...args2) {
			var func2 = args2.pop()
			return perform.apply(this, [...args2, result, func2])
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment