cdsfiui 发表于 2016-07-09 14:24

一个js函数,被直接调用和作为参数传递调用,结果不一样,帮我看看



var foo=function(arg){
    console.log("-->")
    if(typeof(arg)==='function')
      console.log(arg('age'))
    else
      console.log(arg)
}
var f=function(input){console.log(input)}
f('age')
foo(f)
上面这段代码的输出是
age
-->
age
undefined
为什么作为回调的时候,还会多输出一个undefined?
回调会有什么特殊的处理吗?
页: [1]
查看完整版本: 一个js函数,被直接调用和作为参数传递调用,结果不一样,帮我看看