macro definition in javascript

后端 未结 6 685
一向
一向 2021-01-01 22:07

Is there a way that I can define a macro similar to C/C++ macros in Javascript?

I want to use this for debug statements: Something like

#ifdef TEST         


        
6条回答
  •  被撕碎了的回忆
    2021-01-01 22:57

    var de = false; // true when debugging
    function bug( msg ){ ... display msg ... }
    

    Usage:

    de&&bug( "hello world")
    

    When "de" is false (production mode), the overhead is minimal.

提交回复
热议问题