Skip to content

Commit 538f286

Browse files
committed
[css-color] Add forwardToSameClass() guidance to basic 'how to define a method' rules.
1 parent 17453b4 commit 538f286

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

css-color/Overview.bs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,9 +3325,18 @@ Adding New Color-Manipulating Methods</h4>
33253325

33263326
<li>
33273327
Define a forwarding method for all other color classes,
3328-
by calling <code>CSSColor.forward("myMethodName")</code>.
3329-
(This default implementation is not very efficient,
3330-
but it automatically works for all color classes,
3328+
by calling <code>CSSColor.forward("myMethodName")</code>
3329+
or <code>CSSColor.forwardToSameClass("myMethodName")</code>.
3330+
Use <code>forward()</code> if the method returns a non-color value,
3331+
such as a number,
3332+
or if it purposely returns a color value of a particular type,
3333+
like a conversion function.
3334+
Use <code>forwardToSameClass()</code> if the method returns a color,
3335+
and the precise type of color returned doesn't matter,
3336+
as this will ensure it returns the same type of color as it was called on.
3337+
3338+
(These default implementations are not very efficient,
3339+
but they automatically work for all color classes,
33313340
including ones you define
33323341
or that a UA adds in the future.)
33333342

css-color/Overview.html

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,11 +3382,20 @@ <h4 class="heading settled heading" data-level=15.5.1 id=api-adding-methods><spa
33823382

33833383
<li>
33843384
Define a forwarding method for all other color classes,
3385-
by calling <code>CSSColor.forward("myMethodName")</code>.
3386-
(This default implementation is not very efficient,
3387-
but it automatically works for all color classes,
3385+
by calling <code>CSSColor.forward("myMethodName")</code>
3386+
or <code>CSSColor.forwardToSameClass("myMethodName")</code>.
3387+
Use <code>forward()</code> if the method returns a non-color value,
3388+
such as a number,
3389+
or if it purposely returns a color value of a particular type,
3390+
like a conversion function.
3391+
Use <code>forwardToSameClass()</code> if the method returns a color,
3392+
and the precise type of color returned doesn’t matter,
3393+
as this will ensure it returns the same type of color as it was called on.
3394+
3395+
<p>(These default implementations are not very efficient,
3396+
but they automatically work for all color classes,
33883397
including ones you define
3389-
or that a UA adds in the future.)
3398+
or that a UA adds in the future.)</p>
33903399

33913400
<li>
33923401
Optionally, define a more efficient version of the method

0 commit comments

Comments
 (0)