Re: function hoisting like var
Okay then, even shorter. Brendan Eich wrote: > But it is not what you proposed. In what way? Please be more specific, because I don't know what this supposed proposal of mine is. For example, those scope questions mention rebinding in a visible scope, midway through its code block, but that's unrelated to anything I've proposed and unrelated to how JavaScript works. I've tried to guess what you think I've proposed from the scope questions, but the guessing has made my answers long. Stupid mistake, I should have asked instead, sorry. So please say something specific that I can address. > Waldemar wrote a while back: "Keep in mind that function assignments > hoist to the beginning of the scope in which the function is defined, > so your proposal won't work." It works perfectly well. The initial |undefined| is fully intentional, it protects against capture problems. It's a minor limitation, certainly not a showstopper. -- Ingvar von Schoultz ___ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss
Re: How to escape implicit 'with (this)' of a method body
On Aug 1, 2008, at 2:43 PM, Garrett Smith wrote: > What is dynamically inserted? I guess would mean properties added to > an instance of a non-sealed class. Right. Those should not be addressable by unqualified names in method scope -- you have to use "this". >> so all references continue to be >> bound at compile time and this sort of brittleness does not come up? > > I think I remember discussion that 'this' in a static context was > not valid. Maciej meant static in the compile-time or lexical sense, not static in the class singleton object property sense. /be ___ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss
Re: How to escape implicit 'with (this)' of a method body
On Fri, Aug 1, 2008 at 1:03 PM, Maciej Stachowiak <[EMAIL PROTECTED]> wrote: > > On Jul 31, 2008, at 5:24 AM, Dave Herman wrote: > >>> We should take this problem seriously. ... >>> >>> Dynamic scope is very bad. >> >> Specifically: >> >> - Classes are supposed to provide integrity, but dynamic scope makes >> the >> internals of code brittle; any variable reference inside the >> implementation could be subverted by the seemingly innocuous insertion >> of a property. >> >> - Dynamic dispatch has a reasonably understandable cost model, but >> only >> if it's confined to explicit property references. With dynamic scope, >> any variable reference could potentially be very expensive. >> >> - Generally, code within a `with' block is brittle and hard to >> understand, and as Tucker says, the implicit `this.' means that all >> code >> inside class methods is within a `with' block... this means that all >> code inside class methods is brittle! >> >> - In the past, this has been enough for many programmers to deprecate >> all use of `with' -- we should certainly hope to avoid the same >> happening for classes. > > I'm not sure of the benefits on the whole of implicit 'this' for class > methods, but isn't it plausible to apply it only to static properties > and not dynamically inserted ones, What is dynamically inserted? I guess would mean properties added to an instance of a non-sealed class. > so all references continue to be > bound at compile time and this sort of brittleness does not come up? > I think I remember discussion that 'this' in a static context was not valid. If 'this' in a static context points to the class itself, it allows for the possibility of the class having a static method, with a private constructor and a public getInstance method with code something like: >> class E { static function f(){ return new this; } } >> E.f() [object E] Works in the RI. But I there was apparently a reason that that was not good, so that is a bug. http://bugs.ecmascript.org/ticket/74 Garrett > Regards, > Maciej ___ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss
Re: How to escape implicit 'with (this)' of a method body
On Jul 31, 2008, at 5:24 AM, Dave Herman wrote: >> We should take this problem seriously. ... >> >> Dynamic scope is very bad. > > Specifically: > > - Classes are supposed to provide integrity, but dynamic scope makes > the > internals of code brittle; any variable reference inside the > implementation could be subverted by the seemingly innocuous insertion > of a property. > > - Dynamic dispatch has a reasonably understandable cost model, but > only > if it's confined to explicit property references. With dynamic scope, > any variable reference could potentially be very expensive. > > - Generally, code within a `with' block is brittle and hard to > understand, and as Tucker says, the implicit `this.' means that all > code > inside class methods is within a `with' block... this means that all > code inside class methods is brittle! > > - In the past, this has been enough for many programmers to deprecate > all use of `with' -- we should certainly hope to avoid the same > happening for classes. I'm not sure of the benefits on the whole of implicit 'this' for class methods, but isn't it plausible to apply it only to static properties and not dynamically inserted ones, so all references continue to be bound at compile time and this sort of brittleness does not come up? Regards, Maciej ___ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss
Re: How to escape implicit 'with (this)' of a method body
>> >> In AS3, the reference to bar in the zot function would be bound to >> this.bar > > I don't follow. There is no `this.bar` in the class where zot is defined. > Sorry, I said that backwards. When class foo is compiled, there is no member called bar, so the reference is bound to the global variable. Defining a member variable called bar in the subclass does not affect that. I don't know how convention will develop in other environments but, in AS3, global variables are almost always declared in packages, and strict mode is on by default. The result is that you would always get a compiler error in these cases instead of an ambiguous reference. Peter ___ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss