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
(function(){
  // 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);
  }

  alert_ppp();

})();

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 <douglass_da...@earthlink.net> 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 & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to