/**
* {function} fx a function that may or may not return a promise
* {jQuery.Deferred} def the deferred object to fulfill when `fx` completes
* {object} scope the `this` to use inside `fx` (null if static)
* {array} args any args to pass into `fx`
* {*} prevValue result from previous step, undefined for the first step
*/
function(def, scope, args, prevValue) {
try {
// execute the function and evaluate it
var v = fx.apply(scope, [prevValue].concat(args));
if (v instanceof jQuery.Deferred) {
// returned a promise, wait for it to resolve
v.then(function() {
def.resolve.apply(def, arguments);
}, function() {
def.reject.apply(def, arguments);
});
}
else if (v instanceof Error) {
// fx returned an Error, so we know something went wrong
def.reject(v);
}
else {
// no errors thrown and not a promise, resolve immediately
def.resolve(v);
}
}
catch (e) {
// fx threw an Error, so we reject
def.reject(e);
}
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!