Imagine I have X, Y and Z functions, all returning promises and ready to chain. What I want to do is to notify about the progress after they are complete and handle error. What is better to write and why (what are the consequences):
A.
function my_func(index, size){
    return X
        .then(Y)
        .then(Z)
        .then(
           function(data){
               var dfd = new $.Deferred();
               dfd.notify("progress", index / size, 'OK');
               dfd.resolve(data);
               return dfd.promise();
           },
           function(){
               return handleError(arguments, size, index);
           }
        );
}
or
B.
function my_func(index, size){
    var dfd = new $.Deferred();
    X
    .then(Y)
    .then(Z)
    .then(
        function(data){
            dfd.notify("progress", index / size, 'OK');
            dfd.resolve(data);
        },
        function(){
            return handleError(arguments, size, index);
        }
    )
    return dfd.promise();
}
Also, what is the difference between:
X.then(Y).then(Z);
and:
$.when(X).then(Y).than(Z);
If $.when part is unnecessary, why doeas it exist in jQuery at all?
 
     
     
    