Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Minification Issues [duplicate]

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.

like image 870
Lothre1 Avatar asked May 14 '26 08:05

Lothre1


1 Answers

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
like image 171
James Allardice Avatar answered May 16 '26 20:05

James Allardice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!