Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #23602

Re: Declaring global variables

From Joao Rodrigues <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: Declaring global variables
Date 2014-03-14 07:03 -0300
Organization Aioe.org NNTP Server
Message-ID <lfuk56$jju$1@speranza.aioe.org> (permalink)
References <6ae3i9h0e63li3380f0s84pi8h6uque0t3@4ax.com> <property-20140313151743@ram.dialup.fu-berlin.de> <139484623.PyJ8SnIKrL@PointedEars.de> <wssgli3g4uk8$.oosslpxboc6z$.dlg@40tude.net>

Show all headers | View raw


On 13-03-2014 23:46, JJ wrote:
> On Fri, 14 Mar 2014 01:08:25 +0100, Thomas 'PointedEars' Lahn wrote:
>>
>> A very important difference indeed.  Many newcomers think the “window”
>> property is a built-in identical to the global object when it is in fact a
>> host-defined context-dependent property referring to a host object that
>> happens to be in the scope chain in that host environment for historical
>> reasons.
>
> I get the feeling that declaring a global variable, somehow behind the
> scene, became adding a property to the window object.
>
> e.g. global:
>
> var abc=1;
> console.log("abc" in window); //true
>
> Whereas for local context, inside other object...
>
> var obj={
>    fn:function(){
>     var abc=1;
>     console.log("abc" in this); //false
>    }
> };
> obj.fn();

This behaviour is explained in the following MDN article:

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Values,_variables,_and_literals>

Global variables are in fact properties of the global object.

>
> I assume the above behaviour was done in compliance with the DOM specs?
>

I'll pass on that.

-- 
Joao Rodrigues

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Declaring global variables "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-03-13 07:04 -0700
  Re: Declaring global variables "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-03-13 07:39 -0700
    Re: Declaring global variables Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-03-13 16:15 -0300
      Re: Declaring global variables "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-03-13 14:30 -0700
        Re: Declaring global variables Denis McMahon <denismfmcmahon@gmail.com> - 2014-03-13 23:12 +0000
          Re: Declaring global variables "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-03-13 16:53 -0700
  Re: Declaring global variables Martin Honnen <mahotrash@yahoo.de> - 2014-03-13 16:15 +0100
  Re: Declaring global variables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-14 01:08 +0100
    Re: Declaring global variables JJ <duh@nah.meh> - 2014-03-14 09:46 +0700
      Re: Declaring global variables Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-03-14 07:03 -0300

csiph-web