有人可以在“ Angular简介”示例的以下代码中告诉“ ...”是什么吗?
getHeroes() {
this.backend.getAll(Hero).then( (heroes: Hero[]) => {
this.logger.log(`Fetched ${heroes.length} heroes.`);
this.heroes.push(...heroes); // fill cache
});
这与jQuery或Angular无关。这是ES2015中引入的功能。
的这种特殊用法...
实际上没有正式名称。与其他用途一致的名称将是“ spread arguments”(通用术语将是“ spread语法”)。它“爆炸”(传播)一个可迭代对象,并将每个值作为参数传递给该函数。您的示例等效于:
this.heroes.push.apply(this.heroes, Array.from(heroes));
除了更简洁之外,...
这里的另一个优点是可以更轻松地与其他具体参数一起使用:
func(first, second, ...theRest);
// as opposed to the following or something similar:
func.apply(null, [first, second].concat(Array.from(heroes)));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句