Unable to understand javascript syntax

I was looking at react-jsonschema-form code. I stumbled upon the following lines, which I cannot understand.

var formData = (0, _utils.getDefaultFormState)(schema, props.formData, definitions); 

How is the content in the first bracket the function for which the arguments are passed (schema, props.formData, etc.)?

+5
source share
2 answers

I think the answer to this question is that in the first expression (0,_utils.getDefaultFormState) comma , operator evaluates the last argument and returns it.

Thus, the comma operator controls this operand from left to right and returns the most processed operand last right in the expression.

But this is different in terms of using functions and return values.

 // sample from MDN. function myFunc() { var x = 0; return (x += 1, x); // the same as return ++x; } 

As I mentioned in the comment:

The first parentheses are a self- _utils function, and it returns this value as a function of the _utils object, which takes 3 or more arguments.

+1
source

In this context, the first pair of parentheses is a sequence of statements whose value is the value of the last expression. Then:

 (0,_utils.getDefaultFormState) 

returns the objet _utils.getDefaultFormState function, which is then called with the following arguments.

+1
source

Source: https://habr.com/ru/post/1269053/


All Articles