Typescript return 值用花括号包裹?
Typescript return value wrapped in curly braces?
在下面的代码块中 heros
用大括号括起来:
export class InMemoryDataService implements InMemoryDbService {
createDb() {
let heroes = [
{id: 11, name: 'Mr. Nice'},
{id: 12, name: 'Narco'},
...
];
return {heroes};
}
}
具体原因是什么?
是的,你 return 它是一个看起来像这样的对象:
{
heroes: heroes
}
"shortcut"使用这种形式:{ heroes }
。
更多相关信息:Object initializer - New notations in ECMAScript 2015
在下面的代码块中 heros
用大括号括起来:
export class InMemoryDataService implements InMemoryDbService {
createDb() {
let heroes = [
{id: 11, name: 'Mr. Nice'},
{id: 12, name: 'Narco'},
...
];
return {heroes};
}
}
具体原因是什么?
是的,你 return 它是一个看起来像这样的对象:
{
heroes: heroes
}
"shortcut"使用这种形式:{ heroes }
。
更多相关信息:Object initializer - New notations in ECMAScript 2015