Skip to content

Commit dd6cccb

Browse files
authored
Editorial: simplify the example on default toJSON() (#980)
This example was adapted from a previous one in #433, but things are much simpler now and the example makes it seem more complicated than it really is. Make the points inheritance and mixins separately. This also fixes the order of attributes on the returned JSON object, which was wrong the original example. The attributes of the base interface should be included first. Reverse the inheritance order in the example to make this clearer, matching `interface B : A` in two other examples. Fixes #979.
1 parent ecfa7fb commit dd6cccb

File tree

1 file changed

+40
-51
lines changed

1 file changed

+40
-51
lines changed

index.bs

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12090,84 +12090,73 @@ A [=regular operation=] that does not [=have default method steps=] must not be
1209012090

1209112091
<div class=example id=example-tojson-default-inheritance-and-mixins>
1209212092

12093-
The following [=IDL fragment=] defines a number of [=interfaces=],
12094-
which are [=inherited interfaces=] of <code class="idl">A</code>,
12095-
and [=interface mixins=], which are [=included=] by <code class="idl">A</code> or
12096-
by <code class="idl">A</code>'s [=inherited interfaces=],
12097-
as show in the below inheritance tree.
12098-
12099-
<pre>
12100-
C* - M4
12101-
|
12102-
B - M3
12103-
|
12104-
M1 - A - M2*
12105-
</pre>
12106-
12107-
[=Interfaces=] and [=interface mixins=] marked with an asterisk ("*")
12108-
declare a <code>toJSON</code> [=operation=]
12109-
with a [{{Default}}] [=extended attribute=].
12093+
Only [=regular attributes=] of [=interfaces=] that declare a <code>toJSON</code> operation with
12094+
a [{{Default}}] [=extended attribute=] are included, even if an [=inherited interface=] declares
12095+
such a <code>toJSON</code> operation. For example, consider the following [=IDL fragment=]:
1211012096

1211112097
<pre class=webidl>
1211212098
[Exposed=Window]
12113-
interface A : B {
12099+
interface A {
12100+
[Default] object toJSON();
1211412101
attribute DOMString a;
1211512102
};
1211612103

1211712104
[Exposed=Window]
12118-
interface B : C {
12105+
interface B : A {
1211912106
attribute DOMString b;
1212012107
};
1212112108

1212212109
[Exposed=Window]
12123-
interface C {
12110+
interface C : B {
1212412111
[Default] object toJSON();
1212512112
attribute DOMString c;
1212612113
};
12114+
</pre>
1212712115

12128-
interface mixin M1 {
12129-
attribute DOMString m1;
12130-
};
12131-
12132-
interface mixin M2 {
12133-
[Default] object toJSON();
12134-
attribute DOMString m2;
12135-
};
12136-
12137-
interface mixin M3 {
12138-
attribute DOMString m3;
12139-
};
12140-
12141-
interface mixin M4 {
12142-
attribute DOMString m4;
12143-
};
12116+
Calling the <code>toJSON()</code> method of an object implementing interface
12117+
<code class="idl">C</code> defined above would return the following JSON object:
1214412118

12145-
A includes M1;
12146-
A includes M2;
12147-
B includes M3;
12148-
C includes M4;
12119+
<pre highlight=json>
12120+
{
12121+
"a": "...",
12122+
"c": "..."
12123+
}
1214912124
</pre>
1215012125

12151-
Calling the <code>toJSON()</code> method of an object
12152-
implementing interface <code class="idl">A</code> defined above
12153-
would return the following JSON object:
12126+
Calling the <code>toJSON()</code> method of an object implementing interface
12127+
<code class="idl">A</code> (or <code class="idl">B</code>) defined above would return:
1215412128

1215512129
<pre highlight=json>
1215612130
{
12157-
"a": "...",
12158-
"m1": "...",
12159-
"m2": "...",
12160-
"c": "...",
12161-
"m4": "..."
12131+
"a": "..."
1216212132
}
1216312133
</pre>
1216412134

12165-
An object implementing interface <code class="idl">B</code> would return:
12135+
A <code>toJSON</code> operation can also be declared on an [=interface mixin=] (or
12136+
[=partial interface=]) and is equivalent to declaring it on the original [=interface=]. For
12137+
example, consider the following [=IDL fragment=]:
12138+
12139+
<pre class=webidl>
12140+
[Exposed=Window]
12141+
interface D {
12142+
attribute DOMString d;
12143+
};
12144+
12145+
interface mixin M {
12146+
[Default] object toJSON();
12147+
attribute DOMString m;
12148+
};
12149+
12150+
D includes M;
12151+
</pre>
12152+
12153+
Calling the <code>toJSON()</code> method of an object implementing interface
12154+
<code class="idl">D</code> defined above would return:
1216612155

1216712156
<pre highlight=json>
1216812157
{
12169-
"c": "...",
12170-
"m4": "..."
12158+
"d": "...",
12159+
"m": "..."
1217112160
}
1217212161
</pre>
1217312162
</div>

0 commit comments

Comments
 (0)