Can I explicitly reference a JavaScript global variable that's been shadowed by a local with the same name?

前端 未结 5 531
死守一世寂寞
死守一世寂寞 2020-12-10 11:40

I\'ve seen tons of posts about the difference between global and function scope in JavaScript, far too many to link here. I\'ve also seen my exact question asked about Pyth

5条回答
  •  爱一瞬间的悲伤
    2020-12-10 12:21

    There is no standard to do that. For my own purposes, I always put my variables in a container where the name resembles the project name:

    var PROJECT = {}; // Put all "globals" for "project" into this container

    That way, I can collect all variables in one place and if I need to pass the "globals" around, I have to pass at most one reference.

提交回复
热议问题