Skip to content

Instantly share code, notes, and snippets.

@ukyo
Last active August 29, 2015 13:57
Show Gist options
  • Save ukyo/9719763 to your computer and use it in GitHub Desktop.
Save ukyo/9719763 to your computer and use it in GitHub Desktop.
jQuery.Deferredのエラーハンドリングできない問題の一応の解決
// アホすぎ
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