Closed saeidalidadi closed 7 years ago
I can't figure how one deny other.
const obj = {
a: 1
};
const emptyObj = {};
This code above are agree with the two rules.
* No space for empty objects {}
Remove spaces inside brackets when the object is empty.
``` javascript
// don't use
const obj = { };
// use
const obj = {};
For me the rules are correct.
@thebergamo I mean the line:
const user = { name: 'john', email: 'john@example.com' };
Is this true for this rule? No inline object in assignment unless empty.
Well, in this case isn't true. Because when you're assigning an object to a variable is recommended you not using an inline object. The correct statement is:
const user = {
name: 'john',
email: 'john@example.com'
};
Inline objects are used in just two cases, when you're sending as an option in a function not assign for a variable, or assign an empty object to a variable.
the confusion here is that the line
const user = { name: 'john', email: 'john@example.com' };
is there to demonstrate the spacing rule, not to show that it's appropriate to define an object this way. i agree, it's a bit confusing. we can change it to be a function call instead, which is acceptable per style guidelines.
In
style.md
there is two rules for object assignment which deny each other. the two are as bellow: