@@ -23,6 +23,7 @@ spec:css-cascade-5; type:dfn; text:inherit
23
23
spec:dom
24
24
type:dfn; text:aborted flag
25
25
type:method; for:Document; text:getElementsByTagName(qualifiedName)
26
+ type:method; for:Document; text:createElement(qualifiedName)
26
27
spec:html; type:dfn; for:/
27
28
text:focus update steps
28
29
text:task queue
@@ -31,6 +32,8 @@ spec:html; type:element-attr; for:a; text:href
31
32
spec:html; type:event; text:resize
32
33
spec:selectors-4; type:selector; text::hover
33
34
spec:webidl; type:dfn; text:namespace
35
+ spec:uievents
36
+ type:method; for:Document; text:initMouseEvent()
34
37
</pre>
35
38
<!-- Some of these 'anchors' entries are really routing around spec bugs.
36
39
https://github.com/w3c/remote-playback/issues/137
@@ -41,6 +44,7 @@ spec:webidl; type:dfn; text:namespace
41
44
<pre class="anchors">
42
45
urlPrefix: https://dom.spec.whatwg.org/; spec: DOM
43
46
url: #dom-document-getelementsbytagname; type: interface; for: Document; text: getElementsByTagName
47
+ url: #dom-document-createelement; type: interface; for: Document; text: createElement
44
48
urlPrefix: https://w3c.github.io/DOM-Parsing/; spec: DOM-Parsing
45
49
url: #dom-innerhtml-innerhtml; type: attribute; for: Element; text: innerHTML
46
50
urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA262
@@ -59,6 +63,8 @@ urlPrefix: https://url.spec.whatwg.org/; spec: URL
59
63
url: #percent-encode; type: abstract-op; text: percent-encode
60
64
urlPrefix: https://www.w3.org/TR/payment-request/; spec: payment-request
61
65
url: #dfn-state; type: dfn; text: [[state]] ;
66
+ urlPrefix: https://www.w3.org/TR/uievents/ spec: uievents
67
+ url: #idl-interface-MouseEvent-initializers; type: dfn; text: initMouseEvent
62
68
</pre>
63
69
64
70
<style>
@@ -995,7 +1001,7 @@ converting {{undefined}} to the type of the argument.
995
1001
For example, if a boolean argument isn't set,
996
1002
it must default to false.
997
1003
998
- When deciding between different list data types for your API,
1004
+ When deciding between different list data types for your API,
999
1005
unless otherwise required, use the following list types:
1000
1006
1001
1007
* Method list arguments should be of type [=sequence types|sequence<T>=]
@@ -1112,6 +1118,32 @@ and <a href="https://github.com/heycam/webidl/issues/new">File an issue on Web I
1112
1118
if there is some problem with using them.
1113
1119
</div>
1114
1120
1121
+ Factory methods can complement constructors, but generally should not be used *instead* of them.
1122
+ It may still be valuable to include factory methods
1123
+ in addition to constructors, when they provide additional benefits.
1124
+ A common such case is when an API includes base classes
1125
+ and multiple specialized subclasses,
1126
+ with a factory method
1127
+ for creating the appropriate subclass based on the parameters passed.
1128
+ Often the factory method is a static method on the
1129
+ closest common base subclass of the returned result.
1130
+
1131
+ <div class="example">
1132
+ The {{Document/createElement}} method is an example of a
1133
+ factory method that could not have been implemented as a constructor,
1134
+ as its result can be any of a number of subclasses of {{Element}} .
1135
+ If it were designed today, it may have been better to
1136
+ use a static method on {{Element}} (e.g. `Element.create()`)
1137
+ with the document the element is associated with passed in as a parameter.
1138
+ </div>
1139
+
1140
+ <div class="example">
1141
+ The {{Document/initMouseEvent}} factory method only creates {{MouseEvent}} objects,
1142
+ which were originally not constructible,
1143
+ even though there was no technical reason against that.
1144
+ Eventually it was deprecated, and the {{MouseEvent}} object was simply made constructible.
1145
+ </div>
1146
+
1115
1147
<h3 id="synchronous">Use synchronous when appropriate</h3>
1116
1148
1117
1149
Where possible, prefer synchronous APIs when designing a new API.
0 commit comments