- From: Andrew Fedoniouk <news@terrainformatica.com>
- Date: Sun, 02 Jul 2006 10:56:44 -0700
----- Original Message ----- From: "Ian Hickson" <ian@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: Saturday, July 01, 2006 10:21 PM Subject: Re: [whatwg] Canvas 2d methods > On Sat, 1 Jul 2006, Andrew Fedoniouk wrote: >> >> In prototype based languages it is almost impossible to implement 'with' >> effectively in the given notation. >> >> ctx.moveTo(0,0).lineTo(10,10); >> >> is more effective. In some circumstances - in times. > > Why is it more effective for JS? foo.bar() requires lookup only in foo and its proto chain. And with(foo) { bar() } requires lookup in 'with stack', current function namespace and stack of global namespaces. When foo contains bar and you are doing lookup for read these cases are almost identical but if you have something like foo.bar = 1; and with( foo ) { bar = 1; } and foo does not contain that bar you need to scan whole namespace chain (with case). In short 'with' creates additional level of ambiguity. In case of ctx.moveTo(0,0).lineTo(10,10); bytecode structure looks close to this: BC_GET 'ctx' <- put ctx on top of the stack. BC_CALL_METHOD 'moveTo' <- call method 'moveTo' of the object on top of the stack. Put result on top of the stack. BC_CALL_METHOD 'lineTo' <- call method 'lineTo' of the object on top of the stack..... And yet 'with' accepts list of arguments... Andrew Fedoniouk. http://terrainformatica.com
Received on Sunday, 2 July 2006 10:56:44 UTC