2

I've the following code:

getTrainPlanDetail: function(id){
        var df = new $.Deferred();
        $.post( config.api, addJSONHeaders("detail_fiche_entrainement",{"idRequete": id}), function(data){
            if (ajaxEval(data)){
              df.resolve(data);
            } else {
                df.fail(data);
            }
        }, 'json').fail(function(jqXHR, textStatus, errorThrown){
            df.fail();
        });
        return df.promise();
    },

after minification it gets converted into:

getTrainPlanDetail: function(a) {
        var b = new $.Deferred;
        return $.post(config.api, addJSONHeaders("detail_fiche_entrainement", {idRequete: a}), function(a) {
            ajaxEval(a) ? b.resolve(a) : b.fail(a)
        }, "json").fail(function() {
            b.fail()
        }), b.promise()
    }

Do you notice the problem with the return? I want to return the b.promise(); not the $.post Can someone tell me why is this happening? To me it doesn't make sense.

Lothre1
  • 3,050
  • 3
  • 34
  • 53

1 Answers1

9

You are returning b.promise(). The minifier is making use of the comma operator which returns its last operand:

return 1, 2; // returns 2
return 1, 2, 3; // returns 3
James Allardice
  • 156,021
  • 21
  • 318
  • 304
  • Wow, didn't know about that. Thank you. (I'll mark as correct answer when allowed by stackoverflow) – Lothre1 Sep 23 '14 at 08:10