Chinaunix
标题:
一个js函数,被直接调用和作为参数传递调用,结果不一样,帮我看看
[打印本页]
作者:
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?
回调会有什么特殊的处理吗?
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2