MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eixyalq
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
Show parent comments
1
What is that adding it to? Would it not just create an object within that conditional?
1 u/[deleted] Mar 20 '19 Presumably you're spreading it into an object with other properties already existing 1 u/wthit56 Mar 20 '19 Interesting. What would that code look like? 2 u/Thlemaus Mar 21 '19 const test = {attr: true};const obj = {title: 'test',...(test.attr && {valid: 'yes'})}console.log(obj); // Object { title: "test", valid: "yes" } 1 u/wthit56 Mar 21 '19 Oh, I see! That’s cool. I didn’t know you could do that 👍
Presumably you're spreading it into an object with other properties already existing
1 u/wthit56 Mar 20 '19 Interesting. What would that code look like? 2 u/Thlemaus Mar 21 '19 const test = {attr: true};const obj = {title: 'test',...(test.attr && {valid: 'yes'})}console.log(obj); // Object { title: "test", valid: "yes" } 1 u/wthit56 Mar 21 '19 Oh, I see! That’s cool. I didn’t know you could do that 👍
Interesting. What would that code look like?
2 u/Thlemaus Mar 21 '19 const test = {attr: true};const obj = {title: 'test',...(test.attr && {valid: 'yes'})}console.log(obj); // Object { title: "test", valid: "yes" } 1 u/wthit56 Mar 21 '19 Oh, I see! That’s cool. I didn’t know you could do that 👍
2
const test = {attr: true};
const obj = {
title: 'test',
...(test.attr && {valid: 'yes'})
}
console.log(obj); // Object { title: "test", valid: "yes" }
1 u/wthit56 Mar 21 '19 Oh, I see! That’s cool. I didn’t know you could do that 👍
Oh, I see! That’s cool. I didn’t know you could do that 👍
1
u/wthit56 Mar 20 '19
What is that adding it to? Would it not just create an object within that conditional?