-
-
Save fwg/237880 to your computer and use it in GitHub Desktop.
use var!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cron = require('./cron'), sys = require('sys'); | |
cron.Every((2).seconds(), function() { sys.puts('Working!'); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'); | |
function TimeInterval() { | |
this.seconds = 0; | |
this.addTo = function(ti) { | |
this.seconds += ti.seconds; | |
return this; | |
} | |
} | |
var interv = new TimeInterval(); | |
if(interv.seconds == 0) | |
{ | |
sys.puts('Success!'); | |
} | |
var fsinterv = new TimeInterval(); | |
fsinterv.seconds = 5; | |
if(interv.addTo(fsinterv).seconds == 5) | |
{ | |
sys.puts('Success!'); | |
} | |
function generate_multiplier(multiplier) | |
{ | |
return function() { | |
var interval = new TimeInterval(); // use var keyword! | |
interval.seconds = this * multiplier; | |
return interval; | |
} | |
} | |
Number.prototype.seconds = generate_multiplier(1); | |
Number.prototype.minutes = generate_multiplier(60); | |
Number.prototype.hours = generate_multiplier(3600); | |
if((5).seconds().seconds == 5) | |
{ | |
sys.puts('Success!'); | |
} | |
if((5).minutes().seconds == 300) | |
{ | |
sys.puts('Success!'); | |
} | |
if((5).hours().seconds == 18000) | |
{ | |
sys.puts('Success!'); | |
} | |
if((5).minutes().addTo((5).minutes()).seconds == 600) | |
{ | |
sys.puts('Success!'); | |
} | |
exports.Every = function(timeInterval, callback) { | |
setInterval(callback, timeInterval.seconds * 1000); | |
} | |
// Test | |
//exports.Every((5).seconds(), function () { sys.puts("Hi!") }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment