function deferred() {
    var outResolve = function() {}; // will be overwritten
    var outReject = function() {}; // will be overwritten
    var promise = new Promise(function (resolve, reject) {
        outResolve = resolve;
        outReject = reject;
    });
    return {
        promise: promise,
        resolve: outResolve,
        reject: outReject,
    };
}
function deferred() {
    var outResolve = function() {}; 
    var outReject = function() {}; 
    var promise = new Promise(function (resolve, reject) {
        outResolve = resolve;
        outReject = reject;
    });
    return {
        promise: promise,
        resolve: outResolve,
        reject: outReject,
    };
}
function deferred ( ) { var outResolve = function ( ) { } ; // will be overwritten var outReject = function ( ) { } ; // will be overwritten var promise = new Promise ( function ( resolve , reject ) { outResolve = resolve ; outReject = reject ; } ) ; return { promise : promise , resolve : outResolve , reject : outReject , } ; }
helpful script for deferred promise
helpful script for deferred promise