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
Notifications
Mark all as read
Q&A

What is [{options}] in JavaScript?

+0
−2

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?

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+5
−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.

Why does this post require moderator attention?
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 »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!

Like what we're doing? Support us! Donate