首页 > 解决方案 > 找不到不是 es5 的 javascript 行

问题描述

如果我使用这个函数,我会收到一个 uglify 错误,但是如果我将它注释掉,gulp 会很好地构建它。我无法使用 es6。这个函数的哪一部分是“es6”部分?

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...');
        }
    );
  }

标签: javascriptecmascript-6ecmascript-5

解决方案


默认参数是 ES2015 的东西。

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

应该

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

但我强烈建议使用Babel将源代码(现代语法)自动转换为 ES5,而不是尝试手动执行。


推荐阅读