Is there any difference between a global variable and a property of the Global Object

后端 未结 3 796
别那么骄傲
别那么骄傲 2020-12-19 01:23

I was reading the following analysis from David Mark about the js framework \"Sencha\": https://gist.github.com/3279190 and in there he states...

What

3条回答
  •  被撕碎了的回忆
    2020-12-19 01:59

    I'm not aware of any practical difference but there sure is some difference between referencing as global or as window.var. A simple example:

    'use_strict';
    console.info(window.foo);
    console.info(foo);
    

    window.foo will simply return undefined. foo will give undefined as error. So yes, they are different. But in good code(my example is very bad code) it doesn't look like there is any difference. (but if there is, I really like to know more about it :) )

提交回复
热议问题