javascript - I don't quite understand what the form of function parameters means
为情所困
为情所困 2017-07-05 10:47:09
0
2
888

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!

为情所困
为情所困

reply all(2)
大家讲道理

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.
Herebase:?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

  1. base:?string is not TypeScript syntax, base?: String is

  2. fallback 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template