Created
July 11, 2012 19:56
-
-
Save damienklinnert/3092865 to your computer and use it in GitHub Desktop.
basic Step implementation
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
// 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