I saw this snippet here:
render: function(): any {
var thread = this.state.thread;
var name = thread ? thread.name : "";
var messageListItems = this.state.messages.map(getMessageListItem);
return (
<div className="message-section">
<h3 className="message-thread-heading">{name}</h3>
// ...
What does the function(): any{
part in the first line mean?
Apologies if this has been asked before, but it's really hard to search this, particularly when you don't know what it's called.
Points to Remember : JavaScript a function allows you to define a block of code, give it a name and then execute it as many times as you want. A function can be defined using function keyword and can be executed using () operator.
of() The Array. of() method creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments. The difference between Array. of() and the Array constructor is in the handling of integer arguments: Array.
The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s). Basic syntax is: $(selector).action()
A function is simply a “chunk” of code that you can use over and over again, rather than writing it out multiple times. Functions enable programmers to break down or decompose a problem into smaller chunks, each of which performs a particular task.
That's not a part of JavaScript, it's an extra feature added by Flow, a JavaScript preprocessor. TypeScript also has a similar feature.
Essentially, Flow adds a type-checking feature, and to use it you add type-hinting to symbols. In this case, : any
is a type hint for the render
method, meaning the method could return any type.
any
:
any
is a special type annotation that represents the universal dynamic type.any
can flow to any other type, and vice-versa.any
is basically the "get out of my way, I know what I am doing" annotation. Use it when Flow is getting in your way, but you know your program is correct.
A fun little side note, there was a proposed feature in the now-abandoned ES4 draft for type hinting that was very similar to this. As far as I know, it was only ever implemented in the ES-derived ActionScript 3.
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