-
Notifications
You must be signed in to change notification settings - Fork 1
Macros
Neuron Teckid edited this page Mar 21, 2016
·
1 revision
-
__file__: 当前文件名字符串, 包括使用-i编译参数指定的入口文件名; 如果从 stdin 输入, 则取值为null. -
__line__: 当前行号整数.
-
__func__: 当前函数名字符串; 在构造函数中其取值为"ctor"; 不可用于顶级区域或非函数内区域 -
__class__: 当前类名字符串; 不可用于顶级区域或非类内区域 -
__class_func__: 当前类名及函数名字符串, 相当于__class__与__func__以点号 (.) 连接
__debug__: 调试级别整数, 默认为 0, 通过 -D 参数设置, 使得一些语句只在调试时被编译生效.
例子
if __debug__
console.log('value=', value)
在没有 -D 参数指定时, __debug__ 的值为 0, 编译器在执行常量折叠后会直接忽略此分支语句.
也可以与其他条件一同使用, 如
if __debug__ && (expectedValue = undefined)
console.trace('Something weird happens')
当作为 && 操作的左边值 __debug__ 为 0 时, 会执行编译时条件短路, 使条件为 false 从而忽略此分支.