extends class 旁边的 <> 在 JS 中有什么作用?
What does <> next to extends class does in JS?
在 facebooks flux-utils 的例子中,他们做了这样的事情:
import {ReduceStore} from 'flux/utils';
class CounterStore extends ReduceStore<number> {
getInitialState(): number {
return 0;
}
reduce(state: number, action: Object): number {
switch (action.type) {
case 'increment':
return state + 1;
case 'square':
return state * state;
default:
return state;
}
}
}
谁能告诉我 ReduceStore
旁边的 <number>
尖括号在 JS 中的作用?
我试着查了一下,但真的不知道这个 es6 功能叫什么...
感谢所有提供帮助的人!
它不是 ES6 功能,它是 Flow 的一部分,它是 ES6 代码的静态类型检查器。它有点像 TypeScript,因为它添加了新的语法,尽管它们有很大的不同(TypeScript 是成熟的语言)。 Flow 使用 Babel 将您的类型注释转换为纯 ES6。
在 facebooks flux-utils 的例子中,他们做了这样的事情:
import {ReduceStore} from 'flux/utils';
class CounterStore extends ReduceStore<number> {
getInitialState(): number {
return 0;
}
reduce(state: number, action: Object): number {
switch (action.type) {
case 'increment':
return state + 1;
case 'square':
return state * state;
default:
return state;
}
}
}
谁能告诉我 ReduceStore
旁边的 <number>
尖括号在 JS 中的作用?
我试着查了一下,但真的不知道这个 es6 功能叫什么...
感谢所有提供帮助的人!
它不是 ES6 功能,它是 Flow 的一部分,它是 ES6 代码的静态类型检查器。它有点像 TypeScript,因为它添加了新的语法,尽管它们有很大的不同(TypeScript 是成熟的语言)。 Flow 使用 Babel 将您的类型注释转换为纯 ES6。