/**
* Check and invoke callback function
*/
utils
.
invokeCallback
=
function
(
cb
)
{
if
(!!
cb
&&
typeof
cb
===
'function'
)
{
cb
.
apply
(
null
,
Array
.
prototype
.
slice
.
call
(
arguments
,
1
));
}
};
分析:
cb
.
apply
(
null
,
Array
.
prototype
.
slice
.
call
(
arguments
,
1
));
就是
把参数从
index
1
取出来作为回调函数
cb
的参数,调用
使用:
utils.invokeCallback(cb, {code: err.number, msg: err.message}, null);
这里,
{code: err.number, msg: err.message}, null
将被传递给cb 的第一个和第二个参数,
所以,
invokeCallback的参数理论上是依据cb的参数的个数来传递的 ~