为什么jQuery.fx.off返回' undefined'?

时间:2014-09-17 18:32:25

标签: jquery

在jquery中 jQuery.fx.off 将返回bool。但是当我执行以下行时,我得到undefined

alert(jQuery.fx.off);

请告诉我为什么会这样。

1 个答案:

答案 0 :(得分:2)

在最近的版本中,至少jQuery没有为jQuery.fx.off分配初始值,默认情况下保留undefined

jQuery just tests whether it has a value and if that value is truthy

jQuery.speed = function( speed, easing, fn ) {
    // ...

    opt.duration = jQuery.fx.off ? 0 : // ...
        //         ^^^^^^^^^^^^^

要根据真实性获取布尔值,您可以使用Boolean()函数(不含new)或double !!

alert(jQuery.fx.off); // undefined

var fxOff = Boolean(jQuery.fx.off);
alert(fxOff);         // false