This is a note people still stuck in AngularJS-land should probably understand. I see lots of the former in the codebase I've most recently inherited.

From codelord.net:

You donโ€™t need defer to create a simple-valued promise

Letโ€™s take a look at this case:

var defer;
defer = $q.defer();
defer.resolve(['detail', 'simple']);
return defer.promise;

Itโ€™s easy to see the author just wanted to create a promise with some hard-coded value. Those 4 lines? They can just be rewritten as:

return $q.when(['detail', 'simple']);

Labels: ,