相关疑难解决方法(0)

这个符号在JavaScript中意味着什么?

这是什么?

这是一系列关于JavaScript中语法的问题.这也是社区Wiki,因此邀请每个人参与维护此列表.

为什么是这样?

Stack Overflow不允许搜索特定字符.因此,在搜索运算符和其他语法标记时,很难找到许多关于运算符和其他语法标记的问题.这也使得关闭重复更加困难.以下列表是为了解决此问题.

主要思想是在Stack Overflow上链接现有问题,因此我们更容易引用它们,而不是复制ECMAScript规范中的内容.

此外,这是PHP符号引用的公然副本.我们需要一个JS.


请帮忙.编辑并添加指向其他运算符/语法参考的链接,或者如果您无法在特定语法上找到好的问题/答案,请添加此问题的答案并将其链接

javascript

86
推荐指数
1
解决办法
14万
查看次数

ES2015/ES6中的Spread语法与Rest参数

我对ES2015中的spread语法和rest参数感到困惑.任何人都能用适当的例子来解释它们之间的区别吗?

javascript variadic-functions ecmascript-6 spread-syntax

55
推荐指数
5
解决办法
2万
查看次数

数组中的"......"(三点)符号是什么意思?

我不明白这个...符号到底是做什么的.

我尝试了一个简单的例子,用Babel来理解它(查看示例),但似乎:

ES6语法

let myArray = [1, 2, 3, ...18];

console.log(myArray); // [1, 2, 3]
console.log(myArray[4]);// undefined
console.log(myArray.length); // 3
Run Code Online (Sandbox Code Playgroud)

此ES5语法相同:

"use strict";

function _toConsumableArray(arr) { 
    if (Array.isArray(arr)) { 
        for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
             arr2[i] = arr[i];
        }
        return arr2;
     } else { 
        return Array.from(arr); 
     } 
}

var myArray = [1, 2, 3].concat(_toConsumableArray(18));

console.log(myArray); // [1, 2, 3]
console.log(myArray[4]); // undefined
console.log(myArray.length); // 3
Run Code Online (Sandbox Code Playgroud)

但是:这段代码有什么作用?因为output( …

javascript arrays ecmascript-6

29
推荐指数
2
解决办法
2万
查看次数

在javascript中使用rest参数和spread运算符

在ECMAScript 6中添加的rest参数的用途是什么?

例如,在ECMAScript 5中,您可以执行以下操作以从第二个元素开始获取参数数组:

// ES 5
store('Joe', 'money');
store('Jane', 'letters', 'certificates');
function store(name) {
  var items = [].slice.call(arguments, 1); //['money'] in first case
  items.forEach(function (item) {
    vault.customer[name].push(item);
  });
}
Run Code Online (Sandbox Code Playgroud)

这将等同于ECMAScript 6中的以下代码:

// ES 6
store('Joe', 'money');
store('Jane', 'letters', 'certificates');
function store(name, ...items) {
  items.forEach(function (item) {
    vault.customer[name].push(items)
  });
}
Run Code Online (Sandbox Code Playgroud)

它们之间的区别仅仅是语法还是存在性能问题?

也适用于传播运营商(...)

//in ecmascript5
var max = Math.max.apply(null, [14, 3, 77]);
//but in ecmascript6
var max = Math.max(...[14, 3, 77]);
Run Code Online (Sandbox Code Playgroud)

这只是语法更改还是性能问题?

javascript ecmascript-5 ecmascript-6 spread-syntax

15
推荐指数
3
解决办法
8119
查看次数

javascript 三点语法

我正在将Vuetify用于 vue 应用程序,在这个文件中我看到了一个非常奇怪的语法,我找不到它是什么

在第 38 行:

const data = {
    attrs: { disabled: this.disabled },
    class: this.classes,
    props: {},
    directives: [{
      name: 'ripple',
      value: this.ripple || false
    }],
    on: {
      ...(this.$listeners || {}),  // <<<---- here
      click: this.click
    }
  }
Run Code Online (Sandbox Code Playgroud)

谁能说出那三个点是什么?任何关于这方面的文章都会很好

谢谢

javascript vue-component vuejs2 vuetify.js

5
推荐指数
1
解决办法
7110
查看次数

'... paths.js'在'gulp.src([... paths.js,'!gulpfile.babel.js'],{base:'.'}}'中的含义是什么?

我有以下gulp任务:

// Compile ES6 to ES5 and copy to dist
gulp.task('babel', () =>
  gulp.src([...paths.js, '!gulpfile.babel.js'], { base: '.' })
    .pipe(plugins.newer('dist'))
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.babel())
    .pipe(plugins.sourcemaps.write('.', {
      includeContent: false,
      sourceRoot(file) {
        return path.relative(file.path, __dirname);
      }
    }))
    .pipe(gulp.dest('dist'))
);
Run Code Online (Sandbox Code Playgroud)

根据Gulp Doc(gulp.src),我了解到gulp.src会发出匹配提供的glob或glob数组的文件.
但我无法理解'... paths.js'的含义.项目目录中没有以"paths.js"命名的文件.

有没有人可以帮助我理解它?

javascript node.js ecmascript-6 gulp

4
推荐指数
1
解决办法
103
查看次数