Javascript 上的真实宏(Node JS)

Real Macros on Javascript (Node JS)

我想知道我是否可以实现真正的宏。我的意思是在执行前阶段起作用的东西。

为什么?看一看:

如果我想这样想:

1. function isset(obj){
2.    return typeof obj != 'undefined';
3. }
4. 
5. isset(monticuloDeBosta);

"line 5" 将触发错误原因'monticuloDeBosta 未定义。

如果我能做到:

#define isset(x) (typeof x != 'undefined')

考虑到 'isset(monticuloDeBosta)' 将被“(typeof monticuloDeBosta != 'undefined')”替换,它应该可以工作。

Javascript 不支持宏。使用 clojurescript or Parenscript or SweetJS. SweetJS from mozilla is my favourite, its easy to learn and pretty intuitive. To be honest, I havent tried Parenscript and used clojurescript once. Go to sweet's doc here