On Oct 17, 12:08 pm, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
> > It's intuitive because it's like closures work.
> Not really, or at least, not if I understand what you mean.  This
> code, for instance:
> var Thingy = Class.create({
>     initialize: function(name)
>     {
>         this.name = name;
>     },
>     showName: function()
>     {
>         alert("this.name = " + this.name);
>     },
>     doSomething: function()
>     {
>         (function(){
>             alert("this.name = " + this.name);
>         })();
>     }
> });
> If I call it like this:
>     var t;
>     t = new Thingy('Fred');
>     t.showName();
>     t.doSomething();
> ...first alerts "this.name = Fred" (from showName) and then "this.name
> = " (from doSomething).  The closure inside doSomething() does not
> inherit "this" from the scope in which it's called, so "this" is
> "window" within it.  Like all other functions, "this" is determined by
> *how* it's called, not where.
> Granted closures do inherit other aspects of context (in-scope vars
> and such), so if that's what you mean, I take your point.  But I think
> that's a bit apples and oranges.

Well, some people do indeed expect *context* to behave as *scope*.
Some people also confuse these two or believe that one depends on
another in some way : / It's kind of understandable why context would
behave the way scoping (or rather identifier resolution) works. Maybe,
if context was set to the caller's one, we wouldn't have all this
binding mess we have now.

IIRC, Crockford was one of the first people to "complain" about
context semantics (proposing something along the lines of what Tomasz

> > I think you should use simple example in like mine in API Docs to
> > illustrate it's not intuitive.
> Just my two pennies worth, but it worked the way *I* expected it to.
> I haven't been using Prototype that long and I remember not being
> surprised by this, because it worked the way functions in general
> work:  I didn't explicitly supply a context, and it got the global
> object.  So I found it "intuitive" and would be surprised if it were
> something else without me telling it to be.  Just FWIW.
> --
> T.J. Crowder
> tj / crowder software / com


You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 

Reply via email to