[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 ...
>>
>>ctx.scale(2,1)
>>  .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.
>
>-David
>
>  
>
I don't understand the mutable/immutable argument. If I had a mutable 
Point object

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

why should this pattern

Point.setX(1);
Point.setY(2);
Point.setZ(3);

make semantically more sense than

Point.setX(1)
    .setY(2)
    .setZ(3);

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
http://goessner.net







More information about the whatwg mailing list