small medium large xlarge

13 Dec 2013, 21:48
tom s (2 posts)

There are a numbers of examples in the book where you use this form:

var legislating = new $.Deferred();

Others just use the form:

var legislating = $.Deferred();

Can you explain the difference?

13 Dec 2013, 21:58
tom s (2 posts)

I found this in the jquery docs:

The jQuery.Deferred() constructor creates a new Deferred object. The new operator is optional.

This is the kind of thing that peeves me about javascript. There are times when subtle distinctions are totally crucial and times like this when an inconsistency that seems really important is actually meaningless.

Or is there actually a reason to do it one way rather than the other? Based on the docs it seems the use of new is redundant.

28 Oct 2014, 13:54
Eva Smith (1 post)

Use of new is optional.It just instantiating an object legislating in your case. One limitation of the above callback approach is that it can become really cumbersome to write even moderately advanced synchronization logic. And the beauty of it all is that jQuery.Deferred makes it very easy for developers to implement the asynchronous function. Web Apps Design And Development

  You must be logged in to comment