Javascript 对象属性返回NaN,然后使对象函数激发

Javascript 对象属性返回NaN,然后使对象函数激发,javascript,jquery,Javascript,Jquery,我正在练习Javascript,并尝试编写一个对象,当在网页中引用时,该对象将监视用户,并在用户处于非活动状态时将其注销 但是,该对象不能按预期工作。我尝试在强制注销前查看属性min,它返回NaN 我尝试在setTimeout之前将属性设置为0,因为我已经读到在声明时对象还没有值,但它仍然没有递增。。我如何解决这个问题?我混合使用Javascript和Jquery 编辑 我已经解决了NaN问题,但是当我运行注销事件时,我的if不会触发。我的状况有什么问题吗 编辑2 我已将setTimeOut替换

我正在练习Javascript,并尝试编写一个对象,当在网页中引用时,该对象将监视用户,并在用户处于非活动状态时将其注销

但是,该对象不能按预期工作。我尝试在强制注销前查看属性
min
,它返回
NaN

我尝试在setTimeout之前将属性设置为0,因为我已经读到在声明时对象还没有值,但它仍然没有递增。。我如何解决这个问题?我混合使用Javascript和Jquery

编辑 我已经解决了NaN问题,但是当我运行注销事件时,我的if不会触发。我的状况有什么问题吗

编辑2 我已将
setTimeOut
替换为
setInterval

$(document).ready(function () {


/*below object mainly checks if user is inactive*/
var monitorIfActive = {
    minsBeforeForceLogOut : 0, //if this variable reaches threshold, logout commences
    threshold: 5,

    resetInactivity : function(e) {
        monitorIfActive.minsBeforeForceLogOut = 0;           
    },

    userIsInactive : function() {
        monitorIfActive.minsBeforeForceLogout++;
        swal(monitorIfActive.minsBeforeForceLogout.toString());// <- **returns NaN**

        if (monitorIfActive.minsBeforeForceLogout >= monitorIfActive.threshold) 
        {
            monitorIfActive.logout();
        }

    },

    logout: function () {
        swal("You have been logged out due to inactivity");
    }


}

//bind to html
$('body').on('keypress click mousemove scroll', monitorIfActive.resetInactivity);


//start the timer countdown for our monitor object.
monitorIfActive.minsBeforeForceLogOut = 0; //<- I tried this, but still it does not work.
var startMonitoring = setTimeout(monitorIfActive.userIsInactive, 1000); });
$(文档).ready(函数(){
/*下面的对象主要检查用户是否处于非活动状态*/
var监视因子={
minsBeforeForceLogOut:0,//如果此变量达到阈值,则开始注销
阈值:5,
重置不活动:函数(e){
monitorFactive.minsBeforeForeforeLogout=0;
},
userIsInactive:函数(){
monitorFactive.minsBeforeForceLogout++;
swal(monitorIfActive.minsBeforeForceLogout.toString());/=monitorIfActive.threshold)
{
MonitorFactive.logout();
}
},
注销:函数(){
swal(“您因不活动而注销”);
}
}
//绑定到html
$('body')。在('keypress click mousemove scroll',monitorIfActive.resetInactivity')上;
//启动监视器对象的计时器倒计时。

monitorFactive.minsbeforeforeforceLogout=0;//在您的定义中,您有
minsbeforeforeforceLogout
,而在许多其他地方,您有
minsbeforeforeforceLogout
——不同的定义。

在您的定义中,您有
minsbeforeforeforceLogout
,而在许多其他地方,您有
minsbeforeforeforceLogout
out
--不同的camelcasing.

谢谢,这解决了NaN问题..但是你知道如何让这个对象启动注销功能吗?@Malky.Kid当然。使用
setInterval
而不是
setTimeout
--setTimeout只启动一次。非常感谢Jsilv。谢谢,这解决了NaN问题..但是你知道我怎么做吗确保此对象启动注销功能?@Malky.Kid确定。使用
setInterval
而不是
setTimeout
——setTimeout只启动一次。非常感谢Jsilv。