I saw the Facebook F8 app code there is a ":" after the function
function setup(): React.Component {
...
}
What does this mean?
Inheritance?
The colon symbol ( : ) is generally used by JavaScript as a delimiter between key/value pair in an object data type. For example, you may initialize an object named car with key values like brand and color as follows: let car = { brand: "Toyota", color: "red", };
Show activity on this post. (function () {}) creates an anonymous function. Adding the () to the end calls the function that was just created. In the case of this particular function, the anonymous function returns several properties to the Browser object.
The type syntax for declaring a variable in TypeScript is to include a colon (:) after the variable name, followed by its type. Just as in JavaScript, we use the var keyword to declare a variable. Declare its type and value in one statement.
In JavaScript, the functions wrapped with parenthesis are called “Immediately Invoked Function Expressions" or "Self Executing Functions. The purpose of wrapping is to namespace and control the visibility of member functions. It wraps code inside a function scope and decrease clashing with other libraries.
Usually it's flowtype annotation and in this case means that setup()
returns a React.Component. Or it could be TypeScript as well, can't make sophisticated guess in this particular case.
I think that is the return type of the function setup(), if you analyze different examples you will see that syntax in method parameters too
function user(state: State = initialState, action: Action): State {
// some code
return state;
}
edit: is flow, a static type checker from facebook: https://flow.org/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With