Skip to content

Instantly share code, notes, and snippets.

@damienklinnert
Created July 11, 2012 19:55
Show Gist options
  • Save damienklinnert/3092864 to your computer and use it in GitHub Desktop.
Save damienklinnert/3092864 to your computer and use it in GitHub Desktop.
basic Step implementation
// this should work and give us 1 to 5
var Step = function (steps) {
// this only works with arrays, @todo better check
if (typeof steps !== 'object') {
return;
}
var currentStep = 0, lastStep = steps.length;
var execute = function () {
var currentFn = steps[currentStep];
currentStep++;
// set execute to be the objects this pointer
currentFn.call(execute);
};
execute();
};
var callback = function (fn) {
console.log('inside callback and doin nasty stuff');
fn();
};
Step([
function () {
console.log('nr. 1');
callback(this);
},
function () {
console.log('nr. 2');
callback(this);
},
function () {
console.log('nr. 3');
callback(this);
},
function () {
console.log('nr. 4');
// callback(this);
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment