-
-
Notifications
You must be signed in to change notification settings - Fork 389
WebIDL Guide
To specify an interface using WebIDL, you define a <pre class="idl">
block. For example:
<pre class="idl">
interface Request {
readonly attribute ByteString method;
readonly attribute USVString url;
};
</pre>
There are two ways to define an interface.
- Directly, using a
<dfn>
element directly. - Use the
data-dfn-for
attribute on a parent element.
Given interface Request {};
, you can define the interface like so:
<section>
<h2>The <code>Request</code> interface</h2>
<pre class="idl">
interface Request {};
</pre>
<p>The <dfn>Request</dfn> interface represents a request.</p>
<p>An instance of <a>Request</a> allows you to make a request.</a>
</section>
There are multiple ways to define the methods or attributes of an interface:
- Using dot notation, like
<dfn>interfaceName.memberName</dfn>
- Using
data-dfn-for
wrapper attribute.
Given:
<pre class=idl>
interface Request {
readonly attribute USVString url;
Request clone();
};
</pre>
For example, to define Request.url
, you'd write <dfn>Request.url</dfn>
. This also automatically links the IDL declaration to the prose definition.
Similarly, to define the Request.clone()
method, you'd write <dfn>Request.clone</dfn>()</dfn>
.
Alternatively, if you would prefer not to use the dot notation, you can use data-dfn-for
.
The data-dfn-for
attribute allows you to describe one or more aspects of an interface at once.
Similarly, the data-link-for
attribute allows you to link to one or more aspects of an interface at once.
For example, the following defines both the url
and the clone
method.
<p data-dfn-for="Request">
The <dfn>clone()</dfn> method.
The <dfn>url</dfn> attribute.
</p>
<!-- Linking to definitions works the same -->
<p data-link-for="Request">
Links to <a>clone()</a> method.
Links to the <a>url</a> attribute.
</p>
If, for instance, you have two interfaces with methods or attributes that are the same:
<pre class="idl">
interface Request {
readonly attribute USVString url;
};
</pre>
<pre class="idl">
interface Response {
readonly attribute USVString url;
};
</pre>
You explicitly distinguish between them like so:
<section data-dfn-for="Request">
<p>The <dfn>url</dfn> of <a>Request</a>...</p>
</section>
<section data-dfn-for="Response">
<p>The <dfn>url</dfn> of <a>Response</a>...</p>
</section>
We currently don't support:
- linking to constructors (bug 900).
💖 Support ReSpec by becoming a sponsor via Open Collective. 💖
✨ View rendered version of this documentation at https://respec.org/docs/ ✨
- addSectionLinks
- authors
- caniuse
- edDraftURI
- editors
- favicon
- format (markdown)
- formerEditors
- github
- highlightVars
- isPreview
- license
- lint
- localBiblio
- logos
- maxTocLevel
- mdn
- modificationDate
- noTOC
- otherLinks
- pluralize
- postProcess
- preProcess
- previousDiffURI
- previousMaturity
- previousPublishDate
- prevRecShortname
- prevRecURI
-
processVersion(Deprecated) - publishDate
-
refNote(Deprecated) - shortName
- specStatus
- subjectPrefix
- subtitle
- testSuiteURI
- xref
- additionalCopyrightHolders
-
addPatentNote(Deprecated) - alternateFormats
- canonicalURI
- charterDisclosureURI
- copyrightStart
- crEnd
-
darkMode(deprecated, use dark mode) - doJsonLd
- errata
- group
- implementationReportURI
- lcEnd
- level
- noRecTrack
- prevED
- submissionCommentNumber
-
wg(Deprecated) -
wgId(Deprecated) -
wgPatentPolicy(Deprecated) -
wgPatentURI(Deprecated) - wgPublicList
-
wgURI(Deprecated)
a11y
check-punctuation
local-refs-exist
no-headingless-sections
no-http-props
no-unused-vars
no-unused-dfns
informative-dfn
privsec-section
wpt-tests-exist
Handled by ReSpec for you.
- data-abbr
-
data-cite(Not recommended) - data-dfn-for
- data-dfn-type
- data-format
- data-include-format
- data-include-replace
- data-include
- data-link-for
- data-link-type
- data-local-lt
- data-lt-no-plural
- data-lt-noDefault
- data-lt
- data-number
- data-oninclude
- data-sort
- data-tests
-
data-transform(Deprecated) - data-type
- dir
- lang