javascript - 找不到不是 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...');
}
);
}
解决方案
默认参数是 ES2015 的东西。
function ajaxPromise(arr = null){
var self = this;
应该
function ajaxPromise(arr){
if (arr === undefined) {
arr = null;
}
var self = this;
但我强烈建议使用Babel将源代码(现代语法)自动转换为 ES5,而不是尝试手动执行。
推荐阅读
- bash - 如何使用 bash 变量作为 awk 输入文件
- php - 使用通配符、范围和术语进行 Elasticsearch 搜索
- web-scraping - IMPORTXML:查询第一个 Google 搜索结果时“导入的内容为空”
- c# - 使变量成为引用类型
- python - DoesNotExist at /cart/ 匹配查询不存在
- javascript - 火狐显示如果 id="DRCTRY" 则框两次(但如果 id 更改则不会)
- logging - 如何防止 FileLockNodeManager 向 Wildfly 日志发送垃圾邮件?
- excel - 条件格式使用或 if else 语句以绿色或红色突出显示单元格
- python - 2点与垂直线之间的角度
- json - 为什么使用追加的 JSON_MODIFY 未按预期追加