Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjlampstack
23,932 PointsFirst object parameter question....
At 3:40 Guil highlights the first object
{url , method = 'post'} = {}
To me this looks like 2 objects, not 1. Also, why does the first {} have 2 properties, and the second {} has none?
Can someone please clarify. Thanks!
2 Answers
Steven Parker
231,248 PointsThe " = {}
" part at the end defines a default for the parameter. It just means if nothing is provided as an argument, then an empty object will be used instead.
The first one actually defines the structure of the object that is expected, and you're right, it should have two properties. But it also has a default, so if the supplied argument has no "method" property (or if the empty default one is used), one will be created and set to "post".
jlampstack
23,932 PointsI understand it now. Thanks. It just looked funny to me being the first time seeing something like this.
Ken S.
3,838 PointsKen S.
3,838 PointsI had exactly the same question and didn't see this thread first. I guess many ppl have this question!
I understand what it does, but doesn't it seem pretty pointless in the example given?