search

Home  >  Q&A  >  body text

javascript - I don’t quite understand what the form of function parameters means

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!

为情所困为情所困2697 days ago890

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-07-05 10:49:09

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

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-07-05 10:49:09

    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

    reply
    0
  • Cancelreply