On Feb 11, 11: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"

Without seeing the code, only guesses can be provided in response to
that.  It may be that myvar hasn't been assigned a value when you try
to access it, or the code is trying to access a different window
object, or the identifier resolves to a property on some other object,
and so on.


> 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?

Javascript only has 2 scopes: global and function.  However, there can
be more than one global object in a web page (e.g. frames).

There is a long and detailed article on closures here that includes
how scope works:

<URL: http://www.jibbering.com/faq/faq_notes/closures.html >

It is a bit daunting when you first start to read it, but stick at it,
you may take a week or so of solid work to get all the way through and
fully understand it.  But if you take the time, by the end you will
have a very good idea of how identifier (hence scope) and property
name resolution works in javascript.


--
Rob
--~--~---------~--~----~------------~-------~--~----~
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