Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello, I have been experimenting with javascript and I have a question about this:

JavaScript
angular.module('starter.services')
.factory('GameTimerService', function (UtilService) {
    var interval = 1000;


    function doThisEverySecond(myscope, StopTimer)
    {
        if (myscope.rangeValue == 60 || myscope.rangeValue > 5) {
            try {
                MediaService.PlayMedia("sound.mp3");
            }
            catch (e) {
                console.log(e);
            }
            finally {
                StopTimer();
            }
        }
        else {
            myscope.rangeValue++;
        }
    }

    function stopTimer() {
        UtilService.StopTimer();
    }

    return {
        StartTimer : function(myscope) {
            UtilService.StartTimer( function() { doThisEverySecond(myscope, stopTimer); } , interval);
        },

        StopTimer : function()
        {
            stopTimer();
        },
    }
})


It is my angular service and it works great.

But when I change this piece of code:
JavaScript
return {
        StartTimer : function(myscope) {
            UtilService.StartTimer( function() { doThisEverySecond(myscope, stopTimer); } , interval);
        },

        StopTimer : function()
        {
            stopTimer();
        },
    }


for this:

JavaScript
return {
    StartTimer : function(myscope) {
        UtilService.StartTimer( function() { doThisEverySecond(myscope, StopTimer); } , interval);
    },

    StopTimer : function() {
        UtilService.StopTimer();
    },
}


it no longer works.

My question is why?
Posted
Comments
xszaboj 19-Jun-15 11:34am    
the difference is stopTimer vs StopTimer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900