_(下划线)变量的赋值


默认情况下,默认求值器会将最近求值的表达式的结果分配给特殊变量 _(下划线)。 将 _ 显式设置为一个值将禁用此行为。

> [ 'a', 'b', 'c' ]
[ 'a', 'b', 'c' ]
> _.length
3
> _ += 1
Expression assignment to _ now disabled.
4
> 1 + 1
2
> _
4

同样,_error 将引用上次看到的错误,如果有的话。 将 _error 显式设置为一个值将禁用此行为。

> throw new Error('foo');
Error: foo
> _error.message
'foo'

The default evaluator will, by default, assign the result of the most recently evaluated expression to the special variable _ (underscore). Explicitly setting _ to a value will disable this behavior.

> [ 'a', 'b', 'c' ]
[ 'a', 'b', 'c' ]
> _.length
3
> _ += 1
Expression assignment to _ now disabled.
4
> 1 + 1
2
> _
4

Similarly, _error will refer to the last seen error, if there was any. Explicitly setting _error to a value will disable this behavior.

> throw new Error('foo');
Error: foo
> _error.message
'foo'