I have some examples when I write object, It's very hard to select what the best practice(coding style) is.
//destructuring single property
const {foo} = this.state;
const { foo } = this.state;
//destructuring multi properties
const {foo, bar} = this.state;
const { foo, bar } = this.state;
//declaration and initialize single object
const obj = {foo: 'foo'}
const obj = { foo: 'foo' }
const obj = {
foo: 'foo'
}
I know, my question is quite far from the real coding problem.
but I want to know what the better idea for beautify code. (I don't use prettier, or beautify because my company don't use these extension, so I can not use for not changing previous code by the extensions)
//destructuring multi properties
const {
foo,
bar } = this.state;
//declaration and initialize single object
const obj = {
foo: 'foo'
}
this will be more readable if you had more than one key and i think prettier will also beautify code like this.
There is not a "best" answer to this question, and it's probably more of a topic for Reddit than SO.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.