我在第
https://developer.mozilla.org/en/JavaScript/Reference/Operators/Special/void页中无法理解这一段:
This operator allows inserting
expressions that produce side effects
into places where an expression that
evaluates to undefined is desired.
什么是产生副作用的表达?
解决方法
函数通常执行两项操作:执行某些操作并返回值.有些功能只执行其中一项,有些功能同时执行.例如功能:
function square(x) { return x * x; }
副作用是免费的,因为它只是返回一个值,它的调用总是可以用它的返回值代替.另一方面,类似alert()的东西只会被调用它的副作用(警告用户),而不会被调用它的返回值.
那么void运算符的作用是让JavaScript忽略返回值,并声明所有你感兴趣的是函数的副作用.