> 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.
> 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
On Oct 17, 2:53 pm, Tomasz Kalkosiński <[EMAIL PROTECTED]>
wrote:
> On Oct 17, 3:44 pm, kangax <[EMAIL PROTECTED]> wrote:
>
> > Sorry, that's just a poor wording on our side : /
> > By "preserve scope it would have anyway" it was probably meant that a
> > function is not explicitly "bound" to any object.
> > The way you understood binding in this case is actually pretty
> > intuitive to many people.
>
> It's intuitive because it's like closures work. Now I have doubts if
> my other Enumerable methods behave as I intended them to. What do
> others think?
>
> I think you should use simple example in like mine in API Docs to
> illustrate it's not intuitive.
>
> I'm sad :(
> Tomasz Kalkosiński
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---