[whatwg] Canvas 2d methods

Stefan Haustein sh at kobjects.org
Sun Jul 2 15:21:37 PDT 2006


Hi,

I would like to second the request for returning the context in drawing
methods that currently return null.

I think the following example illustrates why "with" is considered harmful:

var lineWidth = 10;
var lineHeight = 20;
with(ctx){
    fillRect(0, 0, lineWidth, lineHeight);
}

Best regards,
Stefan Haustein

Andrew Fedoniouk wrote:
>
> ----- Original Message ----- From: "Ian Hickson" <ian at hixie.ch>
> To: "Andrew Fedoniouk" <news at terrainformatica.com>
> Cc: <vladimir at pobox.com>; "Benjamin Joffe" <canvasgame at gmail.com>; 
> <whatwg at whatwg.org>
> Sent: Sunday, July 02, 2006 2:18 PM
> Subject: Re: [whatwg] Canvas 2d methods
>
>
>> On Sun, 2 Jul 2006, Andrew Fedoniouk wrote:
>>>
>>> 1) if it is declared as
>>> var foo = something;  in current frame then
>>> foo.bar();
>>> foo.baz();
>>> then execution is quite efficient.
>>>
>>> But
>>> with(something)
>>> {
>>>    bar();
>>>    baz();
>>> }
>>>
>>> still requires scan of the whole universe in the worst case.
>>
>> But this isn't the worst case! It's the best case -- you know exactly 
>> what
>> a 2D context's members are.
>>
>>
>>> Consider this:
>>>
>>> with(ctx)
>>> {
>>>    bar( some_var_name );
>>> }
>>>
>>> runtime will scan full chain of ctx for some_var_name. What for?
>>
>> It will scan *exactly* the same places as it would have if you didn't 
>> have
>> the "with", plus the context itself.
>
> And that ctx is pretty heavy thing.
> Again, "with" was considered harmful - that was the inital idea of 
> discussion.
>
>>
>>
>> Anyway, this is all a straw man -- this isn't the reason that the spec
>> doesn't allow this. It doesn't allow this because Safari didn't do it 
>> this
>> way in the first place, and changing it would likely introduce bugs 
>> (while
>> still not helping authors for some time anyway).
>
> As far as I can see return value is not defined at all in:
> http://developer.apple.com/documentation/AppleApplications/Reference/SafariJSRef/Classes/Canvas.html#//apple_ref/js/Canvas.lineTo 
>
> So the proposal is just to define them as returning 'this' instead of 
> nothing.
>
> Andrew Fedoniouk.
> http://terrainformatioca.com
>
>
>
>





More information about the whatwg mailing list