Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript :? operator

I can't figure out what this does or even is. Would someone please be so kind to point me what to research?

circle: (null : ?{ setNativeProps(props: Object): void }),

It's part of a React Native example and is part of a React Native class definition. The outer parts are (abbreviated):

var NavigatorIOSExample = React.createClass({
...
circle: (null : ?{ setNativeProps(props: Object): void }),
...
});

I assume it's some tricky use of the ternary operator. An anonymous function. But?

Source: https://facebook.github.io/react-native/docs/panresponder.html

like image 365
Felix Avatar asked Aug 07 '26 17:08

Felix


1 Answers

The declaration is syntax from Flow. It says that 'circle' is an object with a property that is a function named 'setNativeProps':

{ setNativeProps(props: Object): void }

It also says that circle is nullable (indicated by the preceding '?') and that the default value will be null until an object of the specified type has been assigned to it.

If you look further down the sample you can see how calling code checks that circle has been assigned before calling setNativeProps:

this.circle && this.circle.setNativeProps({
    backgroundColor: CIRCLE_HIGHLIGHT_COLOR
});
like image 69
Jack Avatar answered Aug 10 '26 06:08

Jack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!