Skip to content

Deferred example suggestion #693

Closed
Closed
@jinz2014

Description

@jinz2014

Hi Reviewer,

For the following code at the link http://learn.jquery.com/code-organization/deferreds/examples/,
it is not very clear how defer.resolve and defer.reject work in the function passed to the $.Deferred() method.

Thank you for reading the issue.

var cachedScriptPromises = {};

$.cachedGetScript = function( url, callback ) {
    if ( !cachedScriptPromises[ url ] ) {
        cachedScriptPromises[ url ] = $.Deferred(function( defer ) {
            $.getScript( url ).then( defer.resolve, defer.reject );
        }).promise();
    }
    return cachedScriptPromises[ url ].done( callback );
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions