(function (){ varJtimer =function() { //Init if(Arguments.length >= 1) { This. Setendtime (Arguments[0]); } if(Arguments.length >= 2) { This. Setgeneratecallback (arguments[1]); } }; Jtimer.prototype.setEndTime=function () { if(Arguments.length = = 1) { This. EndTime = Arguments[0];//Date}} Jtimer.prototype.getMillisecond=function () { return This. Endtime.gettime ()-NewDate (). GetTime (); }; Jtimer.prototype.setGenerateCallBack=function(callback) {if(typeofcallback = = "undefined")return; This. Generatecallback =callback; } jtimer.prototype.generate=function () { if(typeof This. Generatecallback = = "undefined")return; varms = This. Getmillisecond (); This. Generatecallback (Math.floor (MSMath.floor (ms/(1000*60*60))%, Math.floor (ms/(1000*60))% of 60, the Math.floor (ms/1000)% 60 ); }; Jtimer.prototype.start=function () { varDelay = 1000; if(Arguments.length = = 1) {Delay= Arguments[0]; } _this= This;//For closure This. Interval =Window.setinterval (function() {_this.generate (); }, delay); } jtimer.prototype.stop=function () { if(typeof This. Interval = = "undefined")return; Window.clearinterval ( This. Interval); This. Interval =undefined; } Window.jtimer=Jtimer;}) ();varJT =NewJtimer (NewDate ("6/27/2016"),function(day, Hour, Min, sec) {Console.log ( day+ "," + Hour + "," + min + "," +( sec);}); Jt.start (1000);
JavaScript Countdown class