1

Hi in the following function, what dos the question mark mean:

  static getCurrentAccessToken(callback: (token: ?FBSDKAccessToken) => void) {
    FBSDKAccessTokenInterface.getCurrentAccessToken((tokenDict) => {
      callback(tokenDict ? new FBSDKAccessToken(tokenDict) : null);
    });
  }

I dont understand this part: (token: ?FBSDKAccessToken)

And yes, this is javascript ES6. Have a look here. Update: this is flow handling javascript.

Nat Mote
  • 3,878
  • 13
  • 28
Chris G.
  • 18,319
  • 35
  • 125
  • 223
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator – Matt Burland Oct 28 '15 at 16:32
  • 9
    Doesn't look like JavaScript to me – j08691 Oct 28 '15 at 16:34
  • That's not JavaScript. Maybe TypeScript? *Edit:* Well, the TypeScript transpiler *seems* to say it's syntactically valid (inside a class), so could be TypeScript. – T.J. Crowder Oct 28 '15 at 16:34
  • 6
    Not a duplicate -- not about the ternary operator at all – Software Engineer Oct 28 '15 at 16:34
  • 3
    http://flowtype.org/docs/nullable-types.html#_ – epascarello Oct 28 '15 at 16:36
  • @Jesse This is not duplicate. mind the terms `a ? b : c` (your link) and the ops question `token: ?FBAccessToken` - thats something different! – Axel Amthor Oct 28 '15 at 16:36
  • @AxelAmthor - Read his code again, `tokenDict ? new FBSDKAccessToken(tokenDict) : null` literally means "is there a tokenDict? Yes? FBSDKAccessToken(tokenDict), no? NULL' – Jesse Oct 28 '15 at 16:38
  • 1
    who cares what language it is, it's called a "ternary operator" in all of them... and that's not javascript, i don't care what anyone says, if it doesn't even parse in V8, it ain't JS AFAIC... – dandavis Oct 28 '15 at 16:39
  • @Jesse don't insist, you're wrong: `static getCurrentAccessToken(` **callback: (token: ?FBSDKAccessToken)** `=> void) {` – Axel Amthor Oct 28 '15 at 16:40
  • Thanks. That was edited in there way after I flagged it and it auto added my comment when flagging. See his edit history – Jesse Oct 28 '15 at 16:41

1 Answers1

2

Thats a nullable type hint for an object variable in flow, as @epascarello already found out.

And as JavaScript doesn't have type hints but even a typeless null, that isn't Javascript at all.

Axel Amthor
  • 10,616
  • 1
  • 20
  • 42