首页 > 解决方案 > javascript/typescript 中的对象返回类型

问题描述

在Angular Tour of Heroes turorial 中,我不明白这种对象返回方式。

 createDb() {
 const heroes = [
   { id: 11, name: 'Dr Nice' },
   { id: 12, name: 'Narco' },
   { id: 13, name: 'Bombasto' },
   { id: 14, name: 'Celeritas' },
   { id: 15, name: 'Magneta' },
   { id: 16, name: 'RubberMan' },
   { id: 17, name: 'Dynama' },
   { id: 18, name: 'Dr IQ' },
   { id: 19, name: 'Magma' },
   { id: 20, name: 'Tornado' }
 ];
 return {heroes}; // <-- this line
}

这是什么意思return {'heroes': heroes}?什么叫这种语法?

标签: javascriptangulartypescriptjavascript-objects

解决方案


这是什么意思{'heroes': heroes}

是的。

什么叫这种语法?

对象属性值简写

https://alligator.io/js/object-property-shorthand-es6/


推荐阅读