Javascript :? operator

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

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

      

This is part of the React Native example and is part of the React Native class definition. External parts (abbreviated):

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

      

I guess this is a tricky use of the ternary operator. Anonymous function. But?

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

+3


source to share


1 answer


Declaration is the syntax of Flow . It says that "circle" is an object with a property called "setNativeProps":

{ setNativeProps(props: Object): void }

      

It also states that the circle is null (denoted by the previous "?") And that the default will be null as long as the object is of the specified type.



If you look further along the sample, you can see how the calling code verifies that the circle has been assigned before calling setNativeProps:

this.circle && this.circle.setNativeProps({
    backgroundColor: CIRCLE_HIGHLIGHT_COLOR
});

      

+8


source







All Articles