export class HashHistory extends History {
constructor (router: VueRouter, base: ?string, fallback: boolean) {
// 调用基类构造器
super(router, base)
}
What does the form of key-value pairs in the constructor parameters in the above code mean when writing, and what does the "?" here in "base: ? string" mean? Could you please give me some advice, thank you!
This is not ES6 syntax, but a type constraint added by flow.js.
flow is a static type checker made by Facebook, which is used to specify variable types in js code. In large JS projects, static types can check many errors in advance.
Here
base:?string
means that the parameter base passed in needs to be a?string
type,?string
is a maybe type, which means that string, null or undefined can be passed in, but if If it is any other type, an error will occur.Vue’s official projects all add flow type constraints.
The official website of flow.js is here https://flow.org/en/docs/gett...
This is obviously not the syntax of ES6. There is no such thing as type in ES6. This looks more like the syntax of TypeScript. The left side of the colon is the parameter name and the right side is the parameter type. The question indicates optional parameters, but if it is said to be TypeScript, There are two grammatical issues here
base:?string
is not TypeScript syntax,base?: String
isfallback
is not an optional parameter, but TypeScript does not allow non-optional parameters to be placed after optional parameters (base?
)I suggest you give me more detailed information