-
-
Notifications
You must be signed in to change notification settings - Fork 393
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>
The recommended way to code up your WebIDL is as follows:
<section data-dfn-for="ExampleInterface" data-link-for="ExampleInterface">
<h2><dfn>ExampleInterface</dfn> interface</h2>
<pre class="idl">
interface ExampleInterface {
void exampleMethod();
readonly attribute USVString url;
};
</pre>
<dl>
<dt><dfn>exampleMethod()</dfn></dt>
<dd>Define <a>exampleMethod()</a> here...</dd>
<dt><dfn>url</dfn></dt>
<dd>Define <a>url</a> here...</dd>
</dl>
</section>
<section data-link-for="ExampleInterface">
<h2>Here is how you link!</h2>
<p>The <a>ExampleInterface</a> or the <a>ExampleInterface.exampleMethod()</a>.</p>
<p>Or like this: <a>exampleMethod</a> - which uses "data-link-for" to link.</p>
</section>
Given interface Request {};
, you can define the interface inside a heading like so:
<section>
<h2><dfn>Request</dfn> interface</h2>
<pre class="idl">
interface Request {};
</pre>
<p>An instance of <a>Request</a> allows you to make a request.</p>
</section>
The above provides convenient linking to the section where the interface is defined.
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>
.
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