Last active
August 29, 2015 13:57
-
-
Save ukyo/9719763 to your computer and use it in GitHub Desktop.
jQuery.Deferredのエラーハンドリングできない問題の一応の解決
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
// アホすぎ | |
function promisify(fn) { | |
return function() { | |
var d = $.Deferred(); | |
try { | |
d.resolve(fn.apply(this, arguments)); | |
} catch (e) { | |
d.reject(e); | |
} | |
return d.promise(); | |
}; | |
} | |
function error() { | |
throw new Error('error!!!!!!!!!!!'); | |
} | |
$.Deferred().resolve().then(promisify(error)).fail(function(e) { | |
console.log('I catch', e.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment