Differed object confusion

The following snippet works as expected:

function boxAnimation() {
        var dfd = $  .Deferred();
        $  ('div').fadeIn('slow', dfd.resolve);
        return dfd.promise();
    }

    $  (function () {
        boxAnimation().done(
            function () { $  (this).animate({ 'margin-top': 50 }); },
            function () { $  (this).animate({ 'margin-left': 150 }); },
            function () { $  (this).animate({ 'margin-top': 250 }); },
            function () { $  (this).animate({ 'margin-left': 350 }); }
        ).fail(function () { alert('failed'); });
    });

However in this one the differed object is neither rejected or resolved. Tell me where am I going wrong. Thanks

function boxAnimation() {
        var dfd = $  .Deferred();
        var randomNum = Math.floor(Math.random() * 5);
        $  ('div').fadeIn('slow', function () {
            if (randomNum == 1) {
                dfd.reject;
            }
            else {
                dfd.resolve;
            }
        });
        return dfd.promise();
    }

    $  (function () {
        boxAnimation().done(
            function () { $  (this).animate({ 'margin-top': 50 }); },
            function () { $  (this).animate({ 'margin-left': 150 }); },
            function () { $  (this).animate({ 'margin-top': 250 }); },
            function () { $  (this).animate({ 'margin-left': 350 }); }
        ).fail(function () { alert('failed'); });
    });

newest questions tagged jquery – Stack Overflow

About Admin

No Comments

Start the ball rolling by posting a comment on this article!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Differed object confusion

The following snippet works as expected:

function boxAnimation() {
        var dfd = $  .Deferred();
        $  ('div').fadeIn('slow', dfd.resolve);
        return dfd.promise();
    }

    $  (function () {
        boxAnimation().done(
            function () { $  (this).animate({ 'margin-top': 50 }); },
            function () { $  (this).animate({ 'margin-left': 150 }); },
            function () { $  (this).animate({ 'margin-top': 250 }); },
            function () { $  (this).animate({ 'margin-left': 350 }); }
        ).fail(function () { alert('failed'); });
    });

However in this one the differed object is neither rejected or resolved. Tell me where am I going wrong. Thanks

function boxAnimation() {
        var dfd = $  .Deferred();
        var randomNum = Math.floor(Math.random() * 5);
        $  ('div').fadeIn('slow', function () {
            if (randomNum == 1) {
                dfd.reject;
            }
            else {
                dfd.resolve;
            }
        });
        return dfd.promise();
    }

    $  (function () {
        boxAnimation().done(
            function () { $  (this).animate({ 'margin-top': 50 }); },
            function () { $  (this).animate({ 'margin-left': 150 }); },
            function () { $  (this).animate({ 'margin-top': 250 }); },
            function () { $  (this).animate({ 'margin-left': 350 }); }
        ).fail(function () { alert('failed'); });
    });

newest questions tagged jquery – Stack Overflow

About Admin

No Comments

Start the ball rolling by posting a comment on this article!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>