Search code examples
javascriptecmascript-6ecmascript-5

Cannot find the line of the javascript that is not es5


I am getting an uglify error if i use this function, however if i comment it out, gulp will build it fine. I am unable to use es6. Which part of this function would be the "es6" part?

function ajaxPromise(arr = null){
    var self = this;

    $.when.apply($,arr)
        .done(function() {
          console.log("hello there, inside the done method of the ajax response");

            }).fail(function(){
          console.log('Something went wrong...');
        }
    );
  }

Solution

  • Default parameters are an ES2015 thing.

    function ajaxPromise(arr = null){
        var self = this;
    

    should be

    function ajaxPromise(arr){
        if (arr === undefined) {
            arr = null;
        }
        var self = this;
    

    But I'd highly recommend using Babel to transpile your source code (in modern syntax) down to ES5 automatically instead of trying to do it manually.