JavaScript中的宏定义 [英] macro definition in javascript
本文介绍了JavaScript中的宏定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以定义类似于Javascript中的C/C ++宏的宏?
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__
#define MYDEBUG(##x) debug(__FILE__,x)
#else
#define debug
#endif
不一定相似,但我想实现该功能.有办法吗?
Not necessarily similar, but I want to acheieve that functionality. Is there a way I can do that?
谢谢
推荐答案
var de = false; // true when debugging
function bug( msg ){ ... display msg ... }
用法:
de&&bug( "hello world")
当"de"为false(生产模式)时,开销最小.
When "de" is false (production mode), the overhead is minimal.
这篇关于JavaScript中的宏定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文