Basically every set of curly braces {} gives you new scope. It does
(give you) with functions and objects, but i am not sure if it does
for "for", "while" etc. The "this" is different for every level of
scope but not every scope (since it points to the current object).

Examine this code

window.ppp = "ppp"; // or ppp = "ppp";
window.self = this; // or self = this;

// make a scope
  // make a local var with the same name
  var ppp = "qqq";
  var self = this;

  // another scope
  function alert_ppp() {
    // access local
    alert("ppp is: " + ppp);
    alert("self is: " + self);
    // access global
    alert("global ppp is: "window.ppp);
    alert("global self is: "window.self);



As you can see globals are indeed available.

And though you have different scopes the "this" is the same (window).
However if you make and object and then have alert_ppp() be its method
you will see the local this points to this object, where as this in a
function outside an object will always point to the global window
(since they are kinda methods to the window object).

I hope that explains a little bit.

As for scope identifier -- arguments.callee would identify your
current function.

On Feb 11, 3:21 am, doug <> wrote:
> I have read about Javascript and scope and I still don't really
> understand it completely, particularly when it comes to Ajax.Updater.
> I don't really understand, for example why, if there is a variable
> window.myvar, some Javascript code would not be able to access it, and
> instead it would be undefined for that code.   I was thinking
> window.myvar was "global"
> But, my question is, is there a way I can do some type of alert() and
> have it print out what scope it is executing in?
> thanks,
> -d

You received this message because you are subscribed to the Google Groups 
"Prototype &" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to