5

I am working on a Chrome extension which has no reason to use jQuery, but which does have a reason to use the meteor-ddp.js script, which uses jQuery only in order to access the $.Deferred functionality. It only uses three methods: reject, resolve and promise:

var conn = new $.Deferred();
//...
conn.reject(err);
//...
conn.resolve(data);
//...
return conn.promise();

Now that JavaScript has its own native Promise objects, it seems unnecessary to include at least 69 KB of jQuery slim.min.js just to provide a promise feature.

It would be great if someone with more experience than I have of jQuery and promises could explain how the $.Deferred functionality works, and how it could be replaced with native Promises.

8
  • 2
    note that you will need a fallback library for some browsers caniuse.com/#feat=promises Commented Sep 18, 2016 at 0:55
  • 1
    I've added a note that this project is for Chrome only Commented Sep 18, 2016 at 1:03
  • Which part do you not understand? As it stands, the question is too broad, you're asking for someone to implement deferred using Promise without giving it a try. Give it a try, and then ask a more focused question. api.jquery.com/jquery.deferred Commented Sep 18, 2016 at 1:15
  • 1
    The script in your link does not require jQuery, and does not use $.Deferred ? Commented Sep 18, 2016 at 1:26
  • @adeneo I've corrected the link Commented Sep 18, 2016 at 18:59

1 Answer 1

8

This would be the equivalent of your code sample in es6:

return new Promise((resolve, reject) => {
  // ...
  reject(err);
  // ...
  resolve(data);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.