by
16
7
2,931
1
Top 1% !
Popular
Famous
Nice
Easy-to-find
Specified
Pattern
Popularity: 4770th place
Languagejavascript
LicenseMIT_X11

PromDuffuhrd.js  wuhrkz  gouuwd.  eY   PruMISe!

best yet....
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/460776/PromDuffuhrd-js--wuhrkz--gouuwd---eY---P?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
(function (GlOb) { function isItArray(ary) { return (ary.prototype === Array); } function foreach(ary, cBak) { if (isItArray(ary)) { for (var i = 0; i < ary.length; i++) { cBak(ary[i]); } } else { cBak(ary); } } function stoopiD(fn) { var status = 'pending', dunMemberz = [], failedMemberz = [], proggyMemberz = [], nArgz = null, promise = { done: function () { for (var i = 0; i < arguments.length; i++) { if (!arguments[i]) { continue; } if (isItArray(arguments[i])) { var ary = arguments[i], j = 0, ln = ary.length; for (; j < ln; j++) { if (status === 'resolved') { ary[j].apply(this, nArgz); } dunMemberz.push(ary[j]); } } else { if (status === 'resolved') { arguments[i].apply(this, nArgz); } dunMemberz.push(arguments[i]); } } return this; }, fail: function () { for (var i = 0; i < arguments.length; i++) { if (!arguments[i]) { continue; } if (isItArray(arguments[i])) { var ary = arguments[i], j = 0, ln = ary.length; for (; j < ln; j++) { if (status === 'rejected') { ary[j].apply(this, nArgz); } failedMemberz.push(ary[j]); } } else { if (status === 'rejected') { arguments[i].apply(this, nArgz); } failedMemberz.push(arguments[i]); } } return this; }, always: function () { return this.done.apply(this, arguments).fail.apply(this, arguments); }, progress: function () { var i = 0, ln = ary.length; for (; i < ln; i++) { if (!arguments[i]) { continue; } if (isItArray(arguments[i])) { var ary = arguments[i], j = 0, ln = ary.length; for (; j < ln; j++) { if (status === 'pending') { proggyMemberz.push(ary[j]); } } } else { if (status === 'pending') { proggyMemberz.push(arguments[i]); } } } return this; }, then: function () { if (arguments.length > 1 && arguments[1]) { this.fail(arguments[1]); } if (arguments.length > 0 && arguments[0]) { this.done(arguments[0]); } if (arguments.length > 2 && arguments[2]) { this.progress(arguments[2]); } }, promise: function (objkt) { if (objkt == null) { return promise; } else { for (var i in promise) { objkt[i] = promise[i]; } return objkt; } }, state: function () { return status; }, isRejected: function () { return status === 'rejected'; }, isResolved: function () { return status === 'resolved'; }, pipe: function (done, fail, progress) { return stoopiD(function (def) { foreach(done, function (func) { if (typeof func === 'function') { deferred.done(function () { var returnval = func.apply(this, arguments); if (returnval && typeof returnval === 'function') { returnval.promise().then(def.resolve, def.reject, def.notify); } else { def.resolve(returnval); } }); } else { deferred.done(def.resolve); } }); foreach(fail, function (func) { if (typeof func === 'function') { deferred.fail(function () { var returnval = func.apply(this, arguments); if (returnval && typeof returnval === 'function') { returnval.promise().then(def.resolve, def.reject, def.notify); } else { def.reject(returnval); } }); } else { deferred.fail(def.reject); } }); }).promise(); } }, deferred = { resolveWith: function (context) { if (status === 'pending') { status = 'resolved'; var argz = (nArgz = (arguments.length > 1) ? arguments[1] : []); for (var i = 0; i < dunMemberz.length; i++) { dunMemberz[i].apply(context, argz); } } return this; }, rejectWith: function (context) { if (status === 'pending') { status = 'rejected'; var argz = (nArgz = (arguments.length > 1) ? arguments[1] : []); for (var i = 0; i < failedMemberz.length; i++) { failedMemberz[i].apply(context, argz); } } return this; }, notifyWith: function (context) { if (status === 'pending') { var argz = (nArgz = (arguments.length > 1) ? arguments[1] : []); for (var i = 0; i < proggyMemberz.length; i++) { proggyMemberz[i].apply(context, argz); } } return this; }, resolve: function () { return this.resolveWith(this, arguments); }, reject: function () { return this.rejectWith(this, arguments); }, notify: function () { return this.notifyWith(this, arguments); } }; var objkt = promise.promise(deferred); if (fn) { fn.call(objkt, objkt); } return objkt; } stoopiD.when = function () { if (arguments.length < 2) { var objkt = arguments.length ? arguments[0] : undefined; if (objkt && (typeof objkt.isResolved === 'function' && typeof objkt.isRejected === 'function')) { return objkt.promise(); } else { return stoopiD().resolve(objkt).promise(); } } else { return (function (argz) { var dufurd = stoopiD(), size = argz.length, done = 0, fuk = new Array(size); var i = 0, ln = ary.length; for (; i < ln; i++) { (function (j) { var objkt = null; if (argz[j].done) { argz[j].done(function () { fuk[j] = (arguments.length < 2) ? arguments[0] : arguments; if (++done == size) { dufurd.resolve.apply(dufurd, fuk); } }) .fail(function () { dufurd.reject(arguments); }); } else { objkt = argz[j]; argz[j] = new Deferred(); argz[j].done(function () { fuk[j] = (arguments.length < 2) ? arguments[0] : arguments; if (++done == size) { dufurd.resolve.apply(dufurd, fuk); } }) .fail(function () { dufurd.reject(arguments); }).resolve(objkt); } })(i); } return dufurd.promise(); })(arguments); } }; GlOb.Deferred = stoopiD; })(window);
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus