推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
shuson
0.21D

求教一个管理 global scope variable 的好的设计代码方式

  •  
  •   shuson · Feb 2, 2015 · 3016 views
    This topic created in 4144 days ago, the information mentioned may be changed or developed.
    现在在维护一段代码,10好几个js文件,一个main.js做入口。而且都是以script tag的src被引入html文件。
    问题是,发现main文件里有很多变量是在其他js文件里定义的全局变量,如果需要找到具体的定义和初始化过程,需要一个一个的文件去浏览才能找到,非常不容易维护。

    请问在处理不同js文件里定义全局变量的时候,怎么处理才能让这样的变量在其他文件中一眼看出来自于哪,进行过怎样的初始过程?
    2 replies    2015-03-04 06:58:22 +08:00
    ryd994
        1
    ryd994  
       Feb 3, 2015 via Android
    能不用就不用
    EthanZ
        2
    EthanZ  
       Mar 4, 2015
    try not to use it at all in the first place.

    In your case, you can create a config file to include all the global variable.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   963 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 22:07 · PVG 06:07 · LAX 15:07 · JFK 18:07
    ♥ Do have faith in what you're doing.