Re: Working Group Decision on ISSUE-131 caret-location-api

On Fri, Apr 29, 2011 at 12:20 PM, Benjamin Hawkes-Lewis
<bhawkeslewis@googlemail.com> wrote:
> We could define some constants on the canvas context interface for use as
> arguments, as with Node.ELEMENT_NODE etc.
>
> Would that be better?

I personally think that arrays of strings are nicer.  Then they don't
have to be globally unique, only unique per-function, so they can be
much shorter.  Thus you could have

    ctx.drawFocusRing(elem, 10, 20, ["canDrawCustom"])

if you want canDrawCustom enabled.  You could make the keyword shorter
if you liked, too.  Sadly, this matches no existing JS APIs I know of
-- they mostly require bitwise or'ing long named constants, as you
suggest.  I think this is an API style that only makes sense in
languages like C, which have no array literal syntax and prefer tiny
performance improvements over big usability improvements.  This kind
of thing is ridiculously verbose (not parameters, but it's the same
idea):

    if (node1.compareDocumentPosition(node2) &
(Node.DOCUMENT_POSITION_CONTAINS |
Node.DOCUMENT_POSITION_CONTAINED_BY)) {

But it's still better than boolean parameters.

(This is a bit of a tangent, though.)

Received on Friday, 29 April 2011 17:21:35 UTC