[whatwg] Canvas 2d methods

Stefan Gössner stefan at goessner.net
Mon Jul 3 16:57:21 PDT 2006

L. David Baron wrote:

>On Sunday 2006-07-02 22:47 +0200, Stefan Gössner wrote:
>>hmm ...
>>  .rotate(Math.PI/4)
>>  .translate(4,-6);
>>illustrates a sequence of manipulations semantically very well, doesn't it?
>In my opinion, this pattern generally makes sense semantically when used
>on immutable objects (e.g., strings in JavaScript).
>I don't think this pattern makes sense for mutable objects.  It just
>suggests immutability.  And making the canvas context objects immutable
>doesn't really make sense without much more significant changes.
I don't understand the mutable/immutable argument. If I had a mutable 
Point object

var Point = {
  setX: function(x) {..},
  setY: function(y) {..},
  setZ: function(z) {..}

why should this pattern


make semantically more sense than


The object's state is altered always in the same *intended* order. And 
the latter doesn't suggest more immutability than the former in my opinion.

The same mechanism applies to the current transformation matrix, which 
is part of the drawing state of the canvas' context object.
Stefan Gössner

More information about the whatwg mailing list