javascript 动态参数判空操作

  我原来是这样写的:

  function foo(x) {

  if(arguments[1]) {

  // do something..

  } else {

  // do other..

  }

  }

  但无论传多少个参数进去,都跳过了 if(arguments[1]) 这一步。快要抓狂的时候,终于成功了。

  function foo(x) {

  if(arguments[1] != undefined) {

  // do something..

  } else {

  // do other..

  }

  }

  想起《Javascript权威指南》里说过,null和undefined有时候是相等的,但有时候是不等的,估计就是指这种情况了。