Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

What is [{options}] in JavaScript?

+1
−3

I am trying to understand this code:

const iframes = iFrameResize( [{options}], [css selector] || [iframe] );

The code can be found in this documentation.

Is [{options}] an array of objects and if so what would be a simple usecase for example?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+8
−0

Given the link where the code comes from (based on your other question), this is just a, let's say, "free-form/pseudo-code/documentation example".

It's not a valid JavaScript code. It's more like a free-format "syntax" intended to provide a general documentation about what parameters are expected for that function.

It's not uncommon to see many documentation pages that uses such format (not only for JavaScript, BTW). For example, many Unix/Linux commands adopt a similar style in their manual pages.

Some documents use brackets to indicate an optional parameter, but I'm not sure if that's the convention used in iFrame Resizer's doc, so read it carefully to see if that's the case.

Some others also use || to indicate that a parameter can have different values and/or different types.

And that's the confusing part, I guess. As that "code" is not actually valid JavaScript code (but only a "free-format-style" documentation example), the brackets does not necessarily mean that it's an array, and the || is not the logical OR operator.


That said, basically, iFrameResize( [{options}], [css selector] || [iframe] ) is just saying (documenting) that iFrameResize can take two arguments, and tells us a little information about them.

The first one is options, which is an object (I'm guessing because it's between {}, and given the example in the same documentation - iFrameResize({ log: true }, '#myIframe') - I guess I'm right). But what kind of object? What data should it have, and what its purpose? Well, you should take a look at the documentation, it has a very detailed description of each possible option value.

The second argument is [css selector] || [iframe], which means that it can be either a CSS selector (AKA a string, such as '#myIframe', that corresponds to the iframe element) or an iframe element (for instance, an element you've got from a call to document.querySelector).


And that's it. There's nothing special about the options object, and its purpose and usage is defined by whatever the iFrameResize function expects. I suggest you to read the docs to see all the use cases. But regarding JavaScript, it's just a simple ("normal") object, just like any other one.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Are the "options" a must there? (4 comments)

Sign up to answer this question »