Re: [geometry] DOMQuad is weird

On Wed, Oct 19, 2016 at 12:00 PM, Simon Fraser <smfr@me.com> wrote:
> As a naive JavaScript author, I would consider a point to be a primitive
> type that's copied by value.
>
> Dean points out that the primitive types are actually DOMPoint.x and
> DOMPoint.y, so what I wrote above is "expected" JS behavior.

Right. Given the attribute-based API, it's generally expected JS
behavior that you can detach an object, alter it, and the parent
object (which is still referencing it) will see that change.  It's the
same behavior you'd get from the original object you passed in to the
constructor.

> Maybe DOMQuad should be entirely read-only, or should return copies
> of points (getP1(), getP2() etc).

That would indeed communicate that the points are likely to be fresh
objects, but it's a rather non-idiomatic thing for such simple
objects.  Readonly is possible, but that precludes some use-cases.

~TJ

Received on Wednesday, 19 October 2016 22:03:06 UTC